/* ==========================================================================
   Heather's Collected Recipes — Retro Betty Crocker Cookbook Theme
   ========================================================================== */

:root {
  --cream: #f7ecd7;
  --cream-light: #fdf6e8;
  --paper: #fbf2df;
  --mustard: #d4a017;
  --mustard-dark: #b3820c;
  --rust: #bc4b27;
  --rust-dark: #9c3a1c;
  --avocado: #74893f;
  --avocado-dark: #59692f;
  --brown: #4a3324;
  --brown-light: #6b4f3a;
  --cardboard: #ecdcb8;
  --line: #c9a86a;
  --shadow: rgba(74, 51, 36, 0.25);

  --font-display: 'Abril Fatface', serif;
  --font-script: 'Yellowtail', cursive;
  --font-body: 'Lora', serif;
  --font-label: 'Josefin Slab', serif;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win over any class's `display` rule
   (e.g. .modal-overlay / .list-panel set display:flex for when they're
   shown) — otherwise elements marked hidden still render and block clicks. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(212, 160, 23, 0.06) 0%, transparent 45%),
    radial-gradient(circle at 85% 75%, rgba(188, 75, 39, 0.06) 0%, transparent 45%),
    repeating-linear-gradient(0deg, rgba(74,51,36,0.015) 0px, rgba(74,51,36,0.015) 1px, transparent 1px, transparent 3px);
  color: var(--brown);
  font-family: var(--font-body);
  min-height: 100vh;
}

img { max-width: 100%; }

/* ===== Header ===== */
.site-header {
  background: linear-gradient(180deg, var(--rust) 0%, var(--rust-dark) 100%);
  color: var(--cream-light);
  position: relative;
  padding: 0 0 34px 0;
  text-align: center;
  box-shadow: 0 4px 12px var(--shadow);
}

.scallop-top {
  height: 22px;
  width: 100%;
  background-image: radial-gradient(circle at 10px 0, transparent 10px, var(--rust) 10.5px);
  background-size: 20px 20px;
  background-position: 0 -10px;
  background-repeat: repeat-x;
}

.header-inner {
  padding: 10px 20px 0;
}

.header-ornament {
  letter-spacing: 10px;
  color: var(--mustard);
  font-size: 14px;
  margin: 6px 0;
}

.site-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.1rem, 6vw, 3.6rem);
  line-height: 1.15;
  margin: 6px 0 4px;
  text-shadow: 2px 2px 0 var(--rust-dark), 0 3px 10px rgba(0,0,0,0.25);
  letter-spacing: 1px;
}

.site-tagline {
  font-family: var(--font-script);
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  color: var(--mustard);
  margin: 0 0 6px;
}

/* ===== Toolbar ===== */
.toolbar-wrap {
  background: var(--cardboard);
  border-bottom: 3px double var(--line);
  padding: 16px 20px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.toolbar {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.search-box {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  background: var(--cream-light);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 6px 14px;
  min-width: 220px;
}

.search-icon { margin-right: 8px; opacity: 0.7; }

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  /* Must stay >=16px: iOS Safari auto-zooms the whole page when a focused
     input's font-size is under 16px, which made the search bar look like
     it was "taking over the screen" on mobile. */
  font-size: 16px;
  color: var(--brown);
  padding: 4px 0;
}

.search-box input::placeholder { color: #a68a6a; }

.clear-search-btn {
  border: none;
  background: none;
  color: var(--rust);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.sort-select {
  font-family: var(--font-label);
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--cream-light);
  padding: 8px 12px;
  color: var(--brown);
  cursor: pointer;
}

.btn {
  font-family: var(--font-label);
  font-weight: 600;
  border: none;
  border-radius: 22px;
  padding: 9px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.2); }
.btn:active { transform: translateY(0); }

.btn-accent {
  background: linear-gradient(180deg, var(--mustard) 0%, var(--mustard-dark) 100%);
  color: var(--brown);
}

.btn-ghost {
  background: var(--cream-light);
  color: var(--brown);
  border: 2px solid var(--line);
}

.btn-icon { font-size: 15px; }

.list-badge {
  background: var(--rust);
  color: white;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 0 5px;
  margin-left: 2px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--avocado-dark);
  font-family: var(--font-label);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 6px 0;
}

.link-btn.danger { color: var(--rust-dark); }

.ingredient-filter-wrap {
  max-width: 1100px;
  margin: 10px auto 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.ingredient-filter-label {
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--brown-light);
  margin-bottom: 8px;
}

.ingredient-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 140px;
  overflow-y: auto;
}

.pill {
  font-family: var(--font-label);
  font-size: 13px;
  background: var(--cream-light);
  border: 1.5px solid var(--avocado);
  color: var(--avocado-dark);
  border-radius: 16px;
  padding: 5px 12px;
  cursor: pointer;
  user-select: none;
}

.pill.active {
  background: var(--avocado);
  color: white;
}

/* ===== Scallop divider ===== */
.scallop-divider {
  height: 16px;
  background-image: radial-gradient(circle at 8px 0, transparent 8px, var(--cardboard) 8.5px);
  background-size: 16px 16px;
  background-position: 0 -8px;
  background-repeat: repeat-x;
}

/* ===== Main content ===== */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 20px 50px;
  min-height: 50vh;
}

.status-bar {
  text-align: center;
  font-family: var(--font-label);
  color: var(--brown-light);
  font-size: 14px;
  margin-bottom: 18px;
}

.loading-state, .error-state, .empty-state {
  text-align: center;
  padding: 60px 20px;
  font-family: var(--font-label);
  color: var(--brown-light);
}

.loading-spinner {
  font-size: 42px;
  animation: sway 1.4s ease-in-out infinite;
  margin-bottom: 10px;
}

@keyframes sway {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

.error-state {
  color: var(--rust-dark);
  background: var(--cream-light);
  border: 2px dashed var(--rust);
  border-radius: 12px;
  max-width: 640px;
  margin: 30px auto;
}

.error-state a { color: var(--rust-dark); font-weight: 700; }

/* ===== Recipe grid & cards ===== */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 26px;
}

.recipe-card {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 18px 18px 16px;
  position: relative;
  cursor: pointer;
  box-shadow: 3px 4px 0 var(--cardboard), 4px 6px 10px var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.recipe-card::before {
  content: '';
  position: absolute;
  top: 10px; left: 0; right: 0;
  height: 0;
  border-top: 1px solid rgba(74,51,36,0.15);
  margin: 0 18px;
}

.recipe-card:nth-child(3n+1) { transform: rotate(-0.6deg); }
.recipe-card:nth-child(3n+2) { transform: rotate(0.5deg); }
.recipe-card:nth-child(3n)   { transform: rotate(-0.3deg); }

.recipe-card:hover {
  transform: rotate(0deg) translateY(-4px) scale(1.015);
  box-shadow: 3px 6px 0 var(--mustard), 6px 10px 18px var(--shadow);
  z-index: 2;
}

.recipe-card-pin {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  filter: drop-shadow(1px 2px 1px rgba(0,0,0,0.3));
}

.recipe-card-title {
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 18px;
  color: var(--rust-dark);
  margin: 8px 0 8px;
  line-height: 1.3;
}

.recipe-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12.5px;
  color: var(--brown-light);
  margin-bottom: 10px;
  font-family: var(--font-label);
}

.recipe-card-meta span { white-space: nowrap; }

.recipe-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
}

.tag-chip {
  font-size: 11px;
  background: var(--avocado);
  color: white;
  border-radius: 10px;
  padding: 2px 9px;
  font-family: var(--font-label);
  opacity: 0.88;
}

.recipe-card-partial {
  font-size: 12px;
  color: var(--rust-dark);
  font-style: italic;
  margin-top: 6px;
}

.recipe-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.add-list-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--avocado-dark);
  cursor: pointer;
}

.add-list-checkbox-label input {
  width: 17px;
  height: 17px;
  accent-color: var(--avocado);
  cursor: pointer;
}

.view-recipe-link {
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--rust-dark);
  text-decoration: none;
  font-weight: 600;
}

/* ===== Footer ===== */
.site-footer {
  background: var(--brown);
  color: var(--cream);
  text-align: center;
  padding: 8px 20px 22px;
  font-family: var(--font-label);
  font-size: 13px;
}

.site-footer .scallop-top {
  background-image: radial-gradient(circle at 10px 0, transparent 10px, var(--brown) 10.5px);
}

.footer-sync { opacity: 0.65; font-size: 11.5px; margin-top: 4px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 22, 14, 0.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  overflow-y: auto;
  padding: 40px 16px;
}

.modal-card {
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 6px;
  max-width: 720px;
  width: 100%;
  position: relative;
  padding: 34px 30px 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: var(--rust);
  color: white;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.recipe-detail-title {
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 26px;
  color: var(--rust-dark);
  margin: 0 0 6px;
  padding-right: 30px;
}

.recipe-detail-source {
  font-size: 12.5px;
  margin-bottom: 14px;
}
.recipe-detail-source a { color: var(--avocado-dark); }

.recipe-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--cardboard);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-family: var(--font-label);
  font-size: 13.5px;
}

.recipe-detail-meta div strong { display: block; color: var(--brown-light); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

.recipe-detail h3 {
  font-family: var(--font-label);
  color: var(--avocado-dark);
  border-bottom: 2px solid var(--mustard);
  padding-bottom: 4px;
  margin: 22px 0 10px;
  font-size: 17px;
}

.recipe-detail ul.ingredient-list { list-style: none; padding: 0; margin: 0; }
.recipe-detail ul.ingredient-list li {
  padding: 5px 0 5px 26px;
  position: relative;
  font-size: 15px;
  line-height: 1.5;
}
.recipe-detail ul.ingredient-list li::before {
  content: '✦';
  position: absolute;
  left: 0;
  color: var(--mustard-dark);
  font-size: 12px;
  top: 8px;
}
.ingredient-section-label {
  font-weight: 700;
  color: var(--rust-dark);
  display: block;
  margin: 10px 0 2px;
  font-family: var(--font-label);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recipe-detail ol.instructions-list { padding-left: 22px; margin: 0; }
.recipe-detail ol.instructions-list li {
  padding: 6px 0;
  line-height: 1.6;
  font-size: 15px;
}

.recipe-detail-notes {
  background: var(--cream-light);
  border-left: 3px solid var(--mustard);
  padding: 10px 14px;
  font-size: 14px;
  font-style: italic;
  color: var(--brown-light);
  margin-top: 8px;
  border-radius: 0 6px 6px 0;
}

.recipe-detail-tags { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 6px; }

.add-list-detail-btn {
  margin-top: 22px;
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
}

.no-ingredients-note {
  background: #fbe9e2;
  border: 1.5px dashed var(--rust);
  color: var(--rust-dark);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
}

/* ===== Shopping List Panel ===== */
.list-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(430px, 100vw);
  background: var(--paper);
  border-left: 3px solid var(--line);
  z-index: 110;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,0.35);
  animation: slideIn 0.22s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.list-panel-header {
  background: var(--avocado);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}
.list-panel-header h2 {
  font-family: var(--font-label);
  margin: 0;
  font-size: 19px;
}
.list-panel-header .modal-close { position: static; background: rgba(255,255,255,0.25); }

.list-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.recipe-chip {
  background: var(--mustard);
  color: var(--brown);
  font-family: var(--font-label);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 14px;
  padding: 5px 8px 5px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.recipe-chip button {
  border: none;
  background: rgba(0,0,0,0.15);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  cursor: pointer;
  color: var(--brown);
  font-size: 11px;
  line-height: 1;
}

.list-empty-msg {
  text-align: center;
  color: var(--brown-light);
  font-family: var(--font-label);
  font-size: 14px;
  padding: 40px 10px;
}

.aggregated-list { }

.agg-group {
  border-bottom: 1px dashed var(--line);
  padding: 10px 0;
}

.agg-group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 15px;
  color: var(--rust-dark);
}

.agg-group-qty { color: var(--avocado-dark); font-size: 14px; }

.agg-group-contributions {
  margin-top: 4px;
  font-size: 12px;
  color: var(--brown-light);
  line-height: 1.5;
}

.list-panel-footer {
  padding: 14px 20px 18px;
  border-top: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-panel-footer .btn { width: 100%; justify-content: center; }

/* ===== Print ===== */
.print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    display: block;
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 20px;
    color: #000;
    font-family: Georgia, serif;
  }
  .print-area h1 { font-size: 22px; border-bottom: 2px solid #000; padding-bottom: 6px; }
  .print-area h2 { font-size: 15px; margin-top: 16px; margin-bottom: 4px; }
  .print-area ul { margin: 0 0 8px; padding-left: 20px; }
  .print-area li { margin-bottom: 3px; }
  .print-area .print-recipes-used { font-size: 11px; color: #555; margin-top: 20px; }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .site-header { padding-bottom: 22px; }
  .header-inner { padding: 4px 16px 0; }
  .header-ornament { font-size: 11px; letter-spacing: 6px; margin: 4px 0; }
  .site-tagline { font-size: 1rem; }

  .toolbar-wrap { padding: 10px 14px 6px; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  /* .search-box uses `flex: 1 1 280px` for the desktop *row* layout (grow to
     fill width, 280px min). In this column layout that same rule means grow
     to fill HEIGHT with a 280px minimum — which is what was making the
     search bar balloon to ~280px tall. Pin it back to content-sized. */
  .search-box { flex: 0 0 auto; padding: 7px 12px; min-width: 0; }

  /* Keep sort / refresh / shopping-list on a single compact row instead of
     stacking full-width (that's what was eating so much vertical space). */
  .toolbar-actions { flex-wrap: nowrap; justify-content: space-between; gap: 8px; }
  .sort-select { flex: 1 1 auto; min-width: 0; padding: 8px 6px; font-size: 13px; }
  #refreshBtn, #openListBtn { padding: 9px 12px; flex: 0 0 auto; }
  .btn-label { display: none; } /* icon-only buttons on phones */

  .ingredient-filter-wrap { margin-top: 8px; padding-top: 8px; }
  .toggle-ingredient-filter, #toggleIngredientFilter { font-size: 12px; }

  .list-panel { width: 100vw; }
  .recipe-detail-meta { flex-direction: column; gap: 8px; }
}

@media (min-width: 641px) {
  /* Never let the icon-only mobile rule leak onto larger screens */
  .btn-label { display: inline; }
}

/* ===== Former inline styles (moved here so the Content-Security-Policy
   can forbid inline style attributes) ===== */
.scallop-flipped { transform: rotate(180deg); }
.recipe-detail ul.ingredient-list li.ingredient-section-row { padding-left: 0; }
.delete-recipe-btn { margin-top: 14px; display: block; width: 100%; text-align: center; }
.print-generated { color: #555; font-size: 12px; }

/* ===== Signed-in user bar (top-right of the header) ===== */
.user-bar {
  position: absolute;
  top: 26px;
  right: 18px;
  font-family: var(--font-label);
  font-size: 13px;
  color: var(--cream-light);
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-bar strong { color: var(--mustard); font-weight: 700; }
.logout-form { display: inline; margin: 0; }
.user-bar-logout {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--cream-light);
  text-decoration: underline;
  cursor: pointer;
}
.user-bar-logout:hover { color: var(--mustard); }
@media (max-width: 640px) {
  .user-bar { position: static; justify-content: center; padding: 4px 12px 0; }
}
