/* ===================== KitCost styles =====================
   Mobile-first, tablet-friendly, desktop fallback.
   Warm, clean, trustworthy. Card-based. No accounting feel.
========================================================== */

:root {
  --orange: #f97316;
  --orange-dark: #ea580c;
  --orange-soft: #fff3e9;
  --green: #16a34a;
  --green-soft: #e9f8ee;
  --bg: #fbf7f2;
  --card: #ffffff;
  --ink: #2b2520;
  --ink-soft: #6b6258;
  --line: #ece4da;
  --danger: #dc2626;
  --blue-soft: #eef4ff;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.06);
  --shadow-lg: 0 6px 22px rgba(60, 40, 20, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --font: "Noto Sans Thai", "Sarabun", "Prompt", -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

/* Harden the [hidden] attribute: components like .field set display, which
   would otherwise override the UA [hidden] rule in real browsers. Open
   states (modals, overflow menu) use classes and remove [hidden], so this
   does not interfere with them. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.3; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 4px;
}
.topbar__logo { font-size: 26px; }
.topbar__name { font-size: 22px; font-weight: 800; color: var(--orange-dark); letter-spacing: 0.5px; }
.topbar__menu-btn {
  width: 44px; height: 44px;
  background: none; border: none;
  display: flex; flex-direction: column; justify-content: center; gap: 5px;
  padding: 10px;
}
.topbar__menu-btn span {
  display: block; height: 3px; border-radius: 3px; background: var(--ink);
}

/* ---------- Nav drawer ---------- */
.nav {
  position: fixed;
  top: 0; right: 0;
  z-index: 60;
  height: 100%;
  width: min(82vw, 320px);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  padding: calc(18px + env(safe-area-inset-top)) 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.nav.open { transform: translateX(0); }
.nav__item {
  text-align: right;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 18px;
  color: var(--ink);
}
.nav__item:hover, .nav__item.active { background: var(--orange-soft); color: var(--orange-dark); }
.nav-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.35);
}

/* ---------- Back-to-home bar ---------- */
.backbar {
  background: var(--bg);
  padding: 12px 16px 0;
  max-width: 960px;
  margin: 0 auto;
}
.backbar__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 16px;
  font-weight: 700;
  color: var(--orange-dark);
  min-height: 44px;
  box-shadow: var(--shadow);
}
.backbar__btn:hover { border-color: var(--orange); }
@media (min-width: 768px) { .backbar { padding-left: 24px; padding-right: 24px; } }

/* ---------- App layout ---------- */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 80px;
}
@media (min-width: 768px) {
  .app { padding: 24px 24px 90px; max-width: 900px; }
}
@media (min-width: 1100px) {
  .app { max-width: 960px; }
}

.view { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity:1; transform:none;} }

.view__title { font-size: 24px; font-weight: 800; color: var(--ink); }
.section-head { font-size: 19px; font-weight: 700; margin-top: 22px; }
.section-hint { color: var(--ink-soft); font-size: 15px; margin: -4px 0 10px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

/* ---------- Hero / Home ---------- */
.hero {
  text-align: center;
  padding: 22px 10px 8px;
}
.hero__logo { font-size: 56px; }
.hero__brand { font-size: 40px; font-weight: 800; color: var(--orange-dark); margin: 6px 0 2px; }
.hero__tagline { font-size: 20px; font-weight: 700; margin: 0 0 8px; }
.hero__msg { color: var(--ink-soft); font-size: 16px; max-width: 30ch; margin: 0 auto; }

.home-primary {
  display: grid;
  gap: 12px;
  margin: 22px 0 16px;
}
.home-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
}
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.chip:hover { border-color: var(--orange); color: var(--orange-dark); }

@media (min-width: 600px) {
  .home-primary { grid-template-columns: 1fr 1fr; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 17px;
  font-weight: 700;
  background: var(--card);
  color: var(--ink);
  min-height: 50px;
  width: 100%;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn__icon { font-size: 20px; }
.btn--big { padding: 18px; font-size: 19px; min-height: 60px; }
.btn--primary { background: var(--orange); color: #fff; box-shadow: var(--shadow); }
.btn--primary:hover { background: var(--orange-dark); }
.btn--secondary { background: var(--orange-soft); color: var(--orange-dark); border-color: #ffd9bd; }
.btn--ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--add {
  background: #fff;
  border: 2px dashed var(--orange);
  color: var(--orange-dark);
  margin-bottom: 8px;
}
.btn--back { width: auto; padding: 8px 14px; min-height: 0; margin-bottom: 10px; }
.btn--mini { width: auto; padding: 9px 14px; min-height: 0; font-size: 15px; }

/* ---------- Fields ---------- */
.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field__label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field__input, .field__select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 17px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
.field__input:focus, .field__select:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-soft);
}

/* ---------- Ingredient cards ---------- */
.ingredient-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.ingredient-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ingredient-card__num {
  font-weight: 700;
  color: var(--orange-dark);
  font-size: 15px;
}
.row-remove {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 8px;
}
.row-remove:hover { background: #fde8e8; }

.source-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.source-toggle button {
  flex: 1;
  background: #faf6f1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px;
  font-size: 14px;
  color: var(--ink-soft);
}
.source-toggle button.active {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}

/* manual fields grid: stack on mobile, 2-col where space allows */
.ing-grid { display: grid; gap: 10px; }
.ing-grid--2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 380px) {
  .ing-grid--2 { grid-template-columns: 1fr; }
}

.ingredient-cost {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}
.ingredient-cost__val { color: var(--green); }
.ingredient-note {
  margin-top: 8px;
  font-size: 14px;
  color: var(--ink-soft);
  background: var(--blue-soft);
  border-radius: 10px;
  padding: 8px 10px;
}
.ingredient-warn {
  margin-top: 8px;
  font-size: 14px;
  color: var(--danger);
  background: #fdecec;
  border-radius: 10px;
  padding: 8px 10px;
}

/* ---------- Packaging rows ---------- */
.packaging-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 130px auto;
  gap: 8px;
  align-items: end;
}
@media (max-width: 420px) {
  .packaging-card { grid-template-columns: 1fr 1fr; }
  .packaging-card .row-remove { grid-column: 1 / -1; justify-self: end; }
}

/* ---------- Misc ---------- */
.misc-toggle { display: grid; gap: 8px; margin-bottom: 12px; }
.radio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 16px;
}
.radio input { width: 20px; height: 20px; accent-color: var(--orange); }

/* ---------- Sticky actions ---------- */
.sticky-actions {
  position: sticky;
  bottom: 0;
  margin: 16px -16px -80px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(251,247,242,0));
}
@media (min-width: 768px) {
  .sticky-actions { margin: 16px 0 0; padding: 0; background: none; position: static; }
}

/* ---------- Result ---------- */
.result-summary { display: grid; gap: 10px; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.result-row__label { color: var(--ink-soft); font-size: 16px; }
.result-row__val { font-weight: 700; font-size: 17px; }
.result-row--big .result-row__val { font-size: 24px; color: var(--orange-dark); }
.result-row--big .result-row__label { font-size: 17px; font-weight: 600; }

.price-cards { display: grid; gap: 12px; }
@media (min-width: 700px) { .price-cards { grid-template-columns: repeat(3, 1fr); } }
.price-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.price-card--mid { border-color: var(--orange); box-shadow: 0 4px 16px rgba(249,115,22,0.18); }
.price-card__tier { font-size: 18px; font-weight: 800; }
.price-card__desc { font-size: 14px; color: var(--ink-soft); min-height: 2.6em; margin: 4px 0 10px; }
.price-card__price { font-size: 32px; font-weight: 800; color: var(--orange-dark); }
.price-card__price small { font-size: 16px; font-weight: 600; }
.price-card__profit { font-size: 15px; color: var(--green); margin-top: 6px; }

.result-actions { display: grid; gap: 10px; margin: 18px 0; }
@media (min-width: 600px) { .result-actions { grid-template-columns: 1fr 1fr; } }

/* ---------- Saved recipes ---------- */
.saved-list, .example-list { display: grid; gap: 14px; }
@media (min-width: 700px) {
  .saved-list, .example-list { grid-template-columns: 1fr 1fr; }
}
.saved-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.saved-card__head { display: flex; align-items: flex-start; gap: 12px; }
.saved-card__headtext { flex: 1; min-width: 0; }
.saved-card__thumb {
  width: 56px; height: 56px;
  flex: 0 0 56px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--orange-soft);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.saved-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.saved-card__emoji { font-size: 30px; line-height: 1; }
.saved-card__name { font-size: 19px; font-weight: 800; }
.fav-badge {
  background: var(--orange-soft);
  color: var(--orange-dark);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.saved-card__cost { font-size: 16px; margin: 6px 0; }
.saved-card__cost b { color: var(--orange-dark); }
.saved-card__prices {
  display: flex; gap: 6px; flex-wrap: wrap; font-size: 14px; color: var(--ink-soft);
  margin-bottom: 8px;
}
.saved-card__prices span {
  background: #faf6f1; border-radius: 8px; padding: 3px 8px;
}
.saved-card__date { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.saved-card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------- Card overflow menu ---------- */
.overflow { position: relative; margin-left: auto; }
.overflow__trigger {
  width: 44px;
  min-width: 44px;
  padding: 9px 0;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 1px;
}
.overflow__menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 20;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;             /* closed by default; not reliant on [hidden] */
  flex-direction: column;
  gap: 2px;
}
.overflow.open .overflow__menu { display: flex; }
.overflow__item {
  text-align: right;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--ink);
  min-height: 46px;
}
.overflow__item:hover { background: var(--orange-soft); color: var(--orange-dark); }
.overflow__item--danger { color: var(--danger); }
.overflow__item--danger:hover { background: #fdecec; color: var(--danger); }

/* ---------- Examples ---------- */
.example-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.example-card__info { display: flex; align-items: center; gap: 12px; }
.example-card__emoji { font-size: 32px; }
.example-card__name { font-weight: 700; font-size: 18px; }

/* ---------- Articles ---------- */
.article-cats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.article-cats .chip { font-size: 14px; padding: 7px 14px; }
.article-cats .chip.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.article-list { display: grid; gap: 12px; }
@media (min-width: 700px) { .article-list { grid-template-columns: 1fr 1fr; } }
.article-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
}
.article-card__cat { font-size: 13px; color: var(--orange-dark); font-weight: 700; }
.article-card__title { font-size: 18px; font-weight: 700; margin: 4px 0 6px; }
.article-card__excerpt { font-size: 15px; color: var(--ink-soft); }

.article-content { line-height: 1.7; }
.article-content h2 { font-size: 24px; }
.article-content h3 { font-size: 19px; margin-top: 18px; }
.article-content p { margin: 0 0 12px; }
.article-content ul { padding-left: 20px; }
.article-content li { margin-bottom: 6px; }
.article-content .callout {
  background: var(--green-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 14px 0;
}

/* ---------- Misc UI ---------- */
.steps { padding-left: 22px; font-size: 18px; }
.steps li { margin-bottom: 12px; }
.lead { font-size: 18px; }
.muted { color: var(--ink-soft); }
.bullets { padding-left: 20px; }
.bullets li { margin-bottom: 6px; }
.contact-list { list-style: none; padding: 0; }
.contact-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.contact-list__label { font-weight: 600; }

.note { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; margin-bottom: 12px; }
.note--info { background: var(--blue-soft); color: #2c4a7c; }
.note--soft { background: var(--green-soft); color: #1f6b3b; }

.support-card__title { font-size: 17px; }
.qr-placeholder {
  height: 180px;
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
  background: #faf6f1;
}
.stat-card { text-align: center; }

/* ---------- Ad slots ---------- */
.ad-slot {
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 22px;
  text-align: center;
  color: var(--ink-soft);
  background: #fff;
  margin: 20px 0;
  font-size: 15px;
}
.ad-slot--mini { padding: 14px; margin: 12px 0; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
}
.empty__emoji { font-size: 48px; }
.empty__title { font-size: 19px; font-weight: 700; color: var(--ink); margin: 10px 0 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: #fff;
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 15px;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
  animation: toastIn 0.2s ease;
}
.toast--warn { background: var(--danger); }
.toast--ok { background: var(--green); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px);} to { opacity:1; transform: translate(-50%,0);} }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }
.modal__box {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal__msg { font-size: 17px; margin-bottom: 18px; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }
.modal__actions--col { flex-direction: column; }
.modal__title { font-size: 19px; font-weight: 800; text-align: center; margin-bottom: 14px; }

/* ---------- Visual picker modal ---------- */
.modal__box--visual { max-width: 400px; max-height: 88vh; overflow-y: auto; }
.visual-preview {
  width: 96px; height: 96px;
  margin: 0 auto 14px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--orange-soft);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.visual-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.visual-preview__emoji { font-size: 52px; line-height: 1; }
.visual-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.visual-tab {
  flex: 1;
  background: #faf6f1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
}
.visual-tab.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.visual-pane { margin-bottom: 16px; }
.icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.icon-choice {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 4px;
  min-height: 72px;
}
.icon-choice.active { border-color: var(--orange); background: var(--orange-soft); }
.icon-choice__emoji { font-size: 28px; line-height: 1; }
.icon-choice__label { font-size: 12px; color: var(--ink-soft); }
#visualImagePane { display: grid; gap: 10px; }
.visual-hint { font-size: 14px; text-align: center; margin: 0; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
