@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=DM+Sans:wght@300;400;500&display=swap');

:root {
  --cream: #f5f0e8;
  --parchment: #ede5d0;
  --bark: #6b4f2e;
  --moss: #4a5e3a;
  --moss-light: #6b8a56;
  --terra: #b85c38;
  --amber: #c9893f;
  --ink: #2a2018;
  --mist: #9e9183;
  --border: rgba(107,79,46,.18);
  --shadow: 0 2px 16px rgba(42,32,24,.10);
  --radius: 12px;
  --tab-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  min-height: 100dvh;
  /* subtle linen texture */
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.03'/%3E%3C/svg%3E");
}

/* ── LAYOUT ── */
.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.app-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--bark);
  letter-spacing: -.02em;
}
.app-header .subtitle {
  font-size: .78rem;
  color: var(--mist);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── TABS ── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  padding: 0 20px;
  gap: 0;
  background: var(--cream);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab-btn {
  flex: 1;
  height: var(--tab-h);
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: .82rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--mist);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .2s, border-color .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.tab-btn.active {
  color: var(--bark);
  border-bottom-color: var(--bark);
}
.tab-btn svg { width: 16px; height: 16px; }

/* ── PANELS ── */
.panel { display: none; flex-direction: column; flex: 1; padding: 16px 20px 80px; }
.panel.active { display: flex; }

/* ── SEARCH BAR ── */
.search-wrap {
  position: relative;
  margin-bottom: 16px;
}
.search-wrap input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: .9rem;
  color: var(--ink);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-wrap input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(201,137,63,.12);
}
.search-wrap .search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mist);
  pointer-events: none;
}

/* ── STATS BAR ── */
.stats-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.stat-chip {
  background: var(--parchment);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .75rem;
  color: var(--bark);
  font-weight: 500;
}

/* ── CUPBOARD ── */
.cupboard-section {
  margin-bottom: 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: white;
  box-shadow: var(--shadow);
}
.cupboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--parchment);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.cupboard-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--bark);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cupboard-count {
  background: var(--bark);
  color: white;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: .7rem;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
}
.chevron { transition: transform .25s; color: var(--mist); }
.cupboard-section.collapsed .chevron { transform: rotate(-90deg); }
.cupboard-body { overflow: hidden; }
.cupboard-section.collapsed .cupboard-body { display: none; }

/* ── JAR ITEM ── */
.jar-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  position: relative;
}
.jar-item:last-child { border-bottom: none; }
.jar-item:active { background: var(--parchment); }

.jar-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--parchment);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.jar-info { flex: 1; min-width: 0; }
.jar-product {
  font-size: .95rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.jar-meta {
  font-size: .75rem;
  color: var(--mist);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.jar-meta span { display: flex; align-items: center; gap: 3px; }
.jar-category-badge {
  display: inline-block;
  font-size: .68rem;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--parchment);
  color: var(--bark);
  font-weight: 500;
  border: 1px solid var(--border);
  margin-top: 4px;
}

.jar-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.action-btn {
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mist);
  transition: all .15s;
  padding: 0;
}
.action-btn:hover { border-color: var(--terra); color: var(--terra); background: #fff5f3; }
.action-btn.move:hover { border-color: var(--moss-light); color: var(--moss); background: #f3f7f0; }

/* ── MODAL ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(42,32,24,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--cream);
  width: 100%;
  max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 40px;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--bark);
  margin-bottom: 16px;
}
.modal select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: .9rem;
  color: var(--ink);
  margin-bottom: 16px;
  outline: none;
  appearance: none;
}
.modal-actions { display: flex; gap: 10px; }

/* ── BUTTONS ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all .2s;
  text-decoration: none;
}
.btn-primary {
  background: var(--bark);
  color: white;
  flex: 1;
}
.btn-primary:hover { background: #7d5c35; }
.btn-secondary {
  background: white;
  color: var(--mist);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--bark); color: var(--bark); }
.btn-danger {
  background: var(--terra);
  color: white;
}
.btn-moss {
  background: var(--moss);
  color: white;
  flex: 1;
}
.btn-moss:hover { background: #3d5030; }

/* ── ADD FORM ── */
.form-section { margin-bottom: 20px; }
.form-section-title {
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--mist);
  font-weight: 500;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: .78rem;
  font-weight: 500;
  color: var(--bark);
  margin-bottom: 5px;
  letter-spacing: .02em;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: .9rem;
  color: var(--ink);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  appearance: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(201,137,63,.12);
}
.field textarea { resize: vertical; min-height: 70px; }

.quantity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
}
.qty-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--parchment);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
}
.qty-btn:hover { border-color: var(--bark); color: var(--bark); }
.qty-display { flex: 1; text-align: center; font-size: 1.2rem; font-weight: 600; color: var(--ink); }
.qty-label { font-size: .75rem; color: var(--mist); }

.submit-row {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--cream) 80%, transparent);
  padding: 16px 0 0;
  margin-top: 8px;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--mist);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }

/* ── FLASH ── */
.flash {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--moss);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: .85rem;
  z-index: 200;
  opacity: 0;
  transition: all .3s;
  white-space: nowrap;
  pointer-events: none;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── HIGHLIGHT ── */
mark {
  background: rgba(201,137,63,.25);
  border-radius: 3px;
  padding: 0 2px;
}

@media (min-width: 521px) {
  .app-shell { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
