/* nutri.wookiewok.win — Design Tokens & Base Styles
   Direction: human-approachable (pantry-first, warm, grounded)
   Palette: cream + dark earth + terracotta accent + olive secondary
   Serif for recipe names, sans for body, mixed icon style */

:root {
  /* ── Color Palette ── */
  --bg:           #F5EFE6;
  --bg-raised:    #FDF9F3;
  --surface:      #FFFFFF;
  --surface-warm: #FAF6EF;
  --fg:           #2A1F17;
  --fg-muted:     #6B5D4F;
  --fg-light:     #9A8B7A;
  --border:       #E6DDD2;
  --border-light: #EDE6DB;
  --accent:       #B85C3C;
  --accent-hover: #A04E32;
  --accent-light: #F0DDD4;
  --secondary:    #6B7C3A;
  --secondary-light: #E8EDDB;
  --success:      #4A8C5C;
  --success-bg:   #E5F2E8;
  --warning:      #C4932A;
  --warning-bg:   #FDF5E0;
  --danger:       #C04040;
  --danger-bg:    #FDE8E8;
  --check:        #6B7C3A;
  --check-bg:     #EEF3E5;
  --struck:       #B8ADA0;

  /* ── Typography ── */
  --font-display: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --font-body:    -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  /* ── Type Scale (fluid) ── */
  --text-xs:    clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);
  --text-sm:    clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --text-base:  clamp(0.9rem, 0.85rem + 0.25vw, 1rem);
  --text-lg:    clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-xl:    clamp(1.15rem, 1rem + 0.5vw, 1.25rem);
  --text-2xl:   clamp(1.3rem, 1.1rem + 0.8vw, 1.5rem);
  --text-3xl:   clamp(1.6rem, 1.3rem + 1.2vw, 1.875rem);
  --text-4xl:   clamp(2rem, 1.5rem + 2vw, 2.5rem);
  --text-5xl:   clamp(2.5rem, 1.8rem + 3vw, 3.5rem);

  /* ── Spacing ── */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* ── Radii ── */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-pill: 9999px;

  /* ── Shadows (warm, subtle) ── */
  --shadow-sm:    0 1px 3px rgba(42, 31, 23, 0.06), 0 1px 2px rgba(42, 31, 23, 0.04);
  --shadow-md:    0 4px 12px rgba(42, 31, 23, 0.08), 0 1px 3px rgba(42, 31, 23, 0.04);
  --shadow-lg:    0 8px 24px rgba(42, 31, 23, 0.10), 0 2px 6px rgba(42, 31, 23, 0.04);
  --shadow-focus: 0 0 0 3px rgba(184, 92, 60, 0.25);

  /* ── Transitions ── */
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --duration:   200ms;
  --duration-lg: 350ms;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  min-height: 100dvh;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--fg);
  letter-spacing: -0.01em;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); font-weight: 600; }

p {
  max-width: 65ch;
  line-height: 1.7;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--duration) var(--ease-out);
}

a:hover {
  color: var(--accent-hover);
}

strong { font-weight: 600; }
small { font-size: var(--text-sm); color: var(--fg-muted); }

/* ── Utility Classes ── */
.text-muted { color: var(--fg-muted); }
.text-light { color: var(--fg-light); }
.text-accent { color: var(--accent); }
.text-secondary { color: var(--secondary); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-display { font-family: var(--font-display); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* ── Layout ── */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.container-sm {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
  min-height: 44px;
  min-width: 44px;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.btn:visited,
.btn-primary:visited,
.btn-secondary:visited,
.btn-ghost:visited,
.btn-icon:visited {
  color: #fff;
}

.btn-secondary:visited {
  color: var(--fg);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-warm);
  border-color: var(--fg-light);
}

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  padding: var(--space-2) var(--space-3);
}

.btn-ghost:hover {
  color: var(--fg);
  background: rgba(42, 31, 23, 0.05);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.btn-icon:hover {
  background: rgba(42, 31, 23, 0.08);
  color: var(--fg);
}

.btn-icon:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn-icon svg {
  width: 24px;
  height: 24px;
}

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  min-height: 36px;
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-base);
  min-height: 52px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  transition: box-shadow var(--duration) var(--ease-out), transform var(--duration) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-flat {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-accent {
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

/* ── Inputs ── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.input-group label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg);
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--fg);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
  min-height: 44px;
}

.input::placeholder {
  color: var(--fg-light);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.input-search {
  padding-left: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239A8B7A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B5D4F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-pill);
  line-height: 1.4;
}

.badge-accent {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-secondary {
  background: var(--secondary-light);
  color: var(--secondary);
}

.badge-muted {
  background: rgba(42, 31, 23, 0.06);
  color: var(--fg-muted);
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

/* ── Checkbox / Strike ── */
.check-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
  flex-shrink: 0;
  color: transparent;
}

.check-btn:hover {
  border-color: var(--check);
  background: var(--check-bg);
}

.check-btn.checked {
  border-color: var(--check);
  background: var(--check);
  color: #fff;
}

.check-btn.checked svg {
  opacity: 1;
}

.check-btn svg {
  width: 18px;
  height: 18px;
  opacity: 0;
  transition: opacity var(--duration) var(--ease-out);
}

/* ── Struck item ── */
.item-struck {
  opacity: 0.45;
}

.item-struck .item-name {
  text-decoration: line-through;
  text-decoration-color: var(--struck);
  text-decoration-thickness: 2px;
}

/* ── Category header ── */
.category-header {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-light);
}

/* ── Navigation ── */
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--fg-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease-out);
}

.nav-link:hover {
  color: var(--fg);
  background: rgba(42, 31, 23, 0.05);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-light);
}

/* ── Bottom nav (mobile) ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-light);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--duration) var(--ease-out);
}

.bottom-nav a:hover,
.bottom-nav a.active {
  color: var(--accent);
}

.bottom-nav a svg {
  width: 24px;
  height: 24px;
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  gap: var(--space-4);
}

.empty-state svg {
  width: 120px;
  height: 120px;
  color: var(--fg-light);
  opacity: 0.4;
}

.empty-state h3 {
  font-size: var(--text-xl);
  color: var(--fg);
}

.empty-state p {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  max-width: 320px;
}

/* ── Autocomplete dropdown ── */
.autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  margin-top: var(--space-1);
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--duration) var(--ease-out);
}

.autocomplete-item:hover {
  background: var(--bg);
}

.autocomplete-item .name {
  font-weight: 500;
  color: var(--fg);
}

.autocomplete-item .category {
  font-size: var(--text-xs);
  color: var(--fg-light);
}

/* ── Stat cards ── */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--fg);
  line-height: 1;
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

.stat-compare {
  font-size: var(--text-xs);
  color: var(--success);
  font-weight: 600;
}

/* ── Recipe card ── */
.recipe-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--duration) var(--ease-out), transform var(--duration) var(--ease-out);
  cursor: pointer;
}

.recipe-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.recipe-card-img {
  width: 100%;
  aspect-ratio: 16/10;
  background: var(--bg);
  object-fit: cover;
}

.recipe-card-body {
  padding: var(--space-4);
}

.recipe-card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
  line-height: 1.3;
}

.recipe-card-meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

/* ── Meal plan slot ── */
.meal-slot {
  min-height: 100px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.meal-slot.filled {
  border-style: solid;
  border-color: var(--border);
  background: var(--surface);
}

/* ── Pantry badge ── */
.pantry-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--secondary);
  background: var(--secondary-light);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-weight: 600;
}

/* ── Share / Copy bar ── */
.action-bar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) 0;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toast-in 0.3s var(--ease-out), toast-out 0.3s var(--ease-out) 2s forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(12px); }
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  margin-bottom: var(--space-4);
}

.page-title {
  font-size: var(--text-2xl);
}

/* ── Section ── */
.section {
  padding: var(--space-12) 0;
}

.section-sm {
  padding: var(--space-8) 0;
}

/* ── Responsive ── */
@media (max-width: 639px) {
  .container { padding: 0 var(--space-4); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .hide-mobile { display: none !important; }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .hide-tablet { display: none !important; }
}

@media (min-width: 1024px) {
  .hide-desktop { display: none !important; }
}

/* ── PWA install prompt ── */
.pwa-prompt {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
}

.pwa-prompt-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.pwa-prompt-text {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--fg);
}

.pwa-prompt-text strong {
  display: block;
  margin-bottom: 2px;
}

/* ── Two-column layout (recipe detail) ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-8);
}

@media (min-width: 768px) {
  .two-col {
    grid-template-columns: 1fr 1.5fr;
  }
}

/* ── Ingredients list ── */
.ingredient-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-light);
}

.ingredient-row:last-child {
  border-bottom: none;
}

.ingredient-qty {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  color: var(--fg);
}

.ingredient-unit {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  min-width: 32px;
}

.ingredient-name {
  flex: 1;
  color: var(--fg);
}

/* ── Nutrient card ── */
.nutrient-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
  background: var(--bg-raised);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

@media (max-width: 639px) {
  .nutrient-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.nutrient-item {
  text-align: center;
  padding: var(--space-2);
}

.nutrient-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.nutrient-label {
  font-size: var(--text-xs);
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Print styles ── */
@media print {
  body { background: #fff; }
  .bottom-nav, .btn, .action-bar, .pwa-prompt { display: none; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
