:root {
  --ink: #19382f;
  --muted: #6d7d77;
  --cream: #f7f3e9;
  --paper: #fffdf8;
  --orange: #ed6a3a;
  --orange-dark: #d95529;
  --line: #dedfd7;
  --sage: #dce7d9;
  --shadow: 0 18px 50px rgba(25, 56, 47, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(237, 106, 58, .08), transparent 23rem),
    var(--cream);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

button, input, select { font: inherit; }
button { color: inherit; }

.topbar {
  height: 82px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(25, 56, 47, .12);
}

.top-actions { display: flex; gap: 10px; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--paper);
  background: var(--ink);
  font-family: Georgia, serif;
  font-size: 22px;
}

.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .08em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.ghost-button, .primary-button, .text-button, .close-button {
  border: 0;
  cursor: pointer;
}

.ghost-button {
  padding: 11px 16px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
}

.ghost-button:hover { background: rgba(25, 56, 47, .06); }

main { padding: 0 clamp(20px, 5vw, 72px) 60px; }

.hero {
  max-width: 1400px;
  margin: 0 auto;
  padding: clamp(50px, 7vw, 95px) 0 54px;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 390px);
  gap: 48px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  max-width: 760px;
  font-family: Georgia, "Noto Serif TC", serif;
  font-size: clamp(46px, 6.4vw, 88px);
  font-weight: 500;
  line-height: .98;
  letter-spacing: -.045em;
}

h1 em { color: var(--orange); font-weight: 500; }

.hero-copy {
  max-width: 570px;
  margin: 27px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.budget-card {
  padding: 26px;
  border-radius: 24px;
  color: var(--paper);
  background: var(--ink);
  box-shadow: var(--shadow);
}

.budget-heading { display: flex; align-items: center; justify-content: space-between; }
.budget-heading span { font-size: 14px; font-weight: 800; }

.currency-label { color: rgba(255,255,255,.72); font-size: 12px; }

.money-input {
  display: flex;
  gap: 8px;
  margin: 25px 0 16px;
  align-items: center;
  font-family: Georgia, serif;
  font-size: 34px;
}

.money-input input {
  min-width: 0;
  width: 100%;
  color: white;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 34px;
  font-weight: 700;
}

.money-input input::placeholder { color: rgba(255, 255, 255, .28); }
.budget-progress { height: 6px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.14); }
.budget-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: #a9ce9e; transition: width .25s; }
.budget-card p { margin: 12px 0 0; color: rgba(255,255,255,.68); font-size: 12px; }

.workspace {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 28px;
  align-items: start;
}

.catalog-panel, .cart-panel {
  border: 1px solid rgba(25, 56, 47, .11);
  border-radius: 28px;
  background: rgba(255, 253, 248, .74);
  box-shadow: 0 8px 35px rgba(25,56,47,.05);
}

.catalog-panel { padding: clamp(22px, 3vw, 36px); }
.cart-panel { position: sticky; top: 20px; overflow: hidden; }

.section-heading, .cart-title, .dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h2 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 29px; font-weight: 500; }

.search {
  min-width: 210px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
}

.search input { width: 100%; border: 0; outline: 0; background: transparent; }

.category-tabs {
  display: flex;
  gap: 9px;
  margin: 28px 0 25px;
  overflow-x: auto;
}

.category-tab {
  flex: 0 0 auto;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}

.category-tab.active { color: white; border-color: var(--ink); background: var(--ink); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.product-card {
  min-height: 184px;
  padding: 19px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--paper);
  transition: transform .2s, border-color .2s, box-shadow .2s;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: #a8b6ae;
  box-shadow: 0 12px 25px rgba(25,56,47,.08);
}

.product-top { display: flex; justify-content: space-between; gap: 8px; }
.product-icon { font-size: 27px; }
.product-category { color: var(--muted); font-size: 11px; }
.product-card h3 { margin: 14px 0 5px; font-size: 16px; }

.lowest-line {
  min-height: 18px;
  margin-top: 5px;
  color: #49803c;
  font-size: 11px;
  font-weight: 800;
}

.price-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--orange);
}

.price-line strong { font-family: Georgia, serif; font-size: 21px; }
.price-line span { color: var(--muted); font-size: 11px; }

.add-button {
  width: 100%;
  margin-top: auto;
  padding: 9px;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.add-button:hover { color: white; background: var(--ink); }

.product-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; margin-top: auto; }
.product-actions .add-button { margin-top: 0; }
.icon-button {
  width: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { background: var(--sage); }

.cart-title { padding: 29px 28px 20px; }
.item-count { padding: 6px 10px; border-radius: 99px; background: var(--sage); font-size: 12px; font-weight: 800; }
.cart-list { max-height: 370px; padding: 0 28px; overflow-y: auto; }

.cart-item {
  padding: 15px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.cart-item-name { margin-bottom: 4px; font-size: 14px; font-weight: 800; }
.cart-item-price { color: var(--muted); font-size: 11px; }
.cart-item-total { text-align: right; font-family: Georgia, serif; font-weight: 700; }

.quantity {
  margin-top: 9px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quantity button { width: 27px; height: 27px; border: 0; background: transparent; cursor: pointer; }
.quantity span { min-width: 28px; text-align: center; font-size: 12px; }
.remove-button { margin-top: 8px; padding: 0; color: var(--muted); border: 0; background: none; cursor: pointer; font-size: 11px; }

.empty-cart { padding: 42px 30px 55px; text-align: center; }
.empty-cart span { display: block; margin-bottom: 14px; font-size: 35px; }
.empty-cart strong { display: block; font-size: 14px; }
.empty-cart p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.cart-summary {
  padding: 23px 28px 28px;
  border-top: 1px solid var(--line);
  background: white;
}

.cart-summary > div, .cart-summary > label {
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.discount-input { display: flex; align-items: center; gap: 3px; }
.discount-input input { width: 42px; padding: 2px; border: 0; border-bottom: 1px solid var(--line); outline: 0; text-align: right; }
.cart-summary .total-row { margin: 18px 0; align-items: baseline; color: var(--ink); font-weight: 800; }
.total-row strong { color: var(--orange); font-family: Georgia, serif; font-size: 27px; }

.primary-button {
  width: 100%;
  padding: 13px 18px;
  color: white;
  border-radius: 12px;
  background: var(--orange);
  font-weight: 800;
}

.primary-button:hover { background: var(--orange-dark); }
.primary-button:disabled { cursor: not-allowed; opacity: .42; }
.text-button { width: 100%; margin-top: 12px; color: var(--muted); background: none; font-size: 12px; }
.text-button:disabled { opacity: .35; cursor: not-allowed; }

.hidden { display: none !important; }
.empty-state { padding: 50px; color: var(--muted); text-align: center; }

dialog {
  width: min(92vw, 470px);
  padding: 0;
  color: var(--ink);
  border: 0;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 25px 80px rgba(25,56,47,.3);
}

dialog::backdrop { background: rgba(11,28,23,.6); backdrop-filter: blur(4px); }
dialog form { padding: 28px; }
.close-button { font-size: 30px; background: none; }

dialog form > label, .form-row label {
  margin-top: 20px;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dialog input, dialog select {
  width: 100%;
  padding: 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: white;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog form .primary-button { margin-top: 24px; }

.danger-button {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  color: #a43b2a;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.history-wrap { padding: 28px; }
.price-stats {
  margin: 24px 0 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.price-stat { padding: 15px; border-radius: 14px; background: var(--sage); }
.price-stat span { display: block; color: var(--muted); font-size: 11px; }
.price-stat strong { display: block; margin-top: 4px; font-family: Georgia, serif; font-size: 22px; }
.history-list { max-height: 300px; overflow-y: auto; border-top: 1px solid var(--line); }
.history-row {
  padding: 13px 4px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.history-row strong { color: var(--orange); }
.history-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.best-badge { margin-left: 6px; padding: 2px 6px; color: #37702c; border-radius: 99px; background: #dcebd7; font-size: 9px; }
.dialog-note, .share-copy { color: var(--muted); font-size: 12px; line-height: 1.7; }
.share-copy { margin: 22px 0; font-size: 14px; }
.share-actions { display: grid; gap: 10px; }
.import-button {
  display: block;
  padding: 12px 18px;
  border: 1px solid var(--ink);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  font-weight: 800;
}
.import-button input { display: none; }

.month-picker {
  margin: 22px 0 14px;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.monthly-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.monthly-stat {
  padding: 14px 10px;
  border-radius: 14px;
  background: var(--sage);
  text-align: center;
}
.monthly-stat span { display: block; color: var(--muted); font-size: 10px; }
.monthly-stat strong { display: block; margin-top: 5px; font-family: Georgia, serif; font-size: 18px; }
.monthly-products, .monthly-purchases { margin-top: 22px; }
.monthly-section-title { margin: 0 0 8px; font-size: 13px; }
.monthly-product-row, .monthly-purchase-row {
  padding: 10px 2px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.monthly-product-row small, .monthly-purchase-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}
.monthly-product-row strong, .monthly-purchase-row strong { color: var(--orange); }
.monthly-empty { padding: 28px 0; color: var(--muted); text-align: center; font-size: 13px; }

.receipt { padding: 32px 34px 20px; }
.receipt-head { padding-bottom: 20px; text-align: center; border-bottom: 1px dashed #bbb; }
.receipt-head h2 { margin-bottom: 7px; }
.receipt-head p { margin: 0; color: var(--muted); font-size: 11px; }
.receipt-lines { padding: 16px 0; border-bottom: 1px dashed #bbb; }
.receipt-line { margin: 9px 0; display: grid; grid-template-columns: 1fr auto; gap: 10px; font-size: 13px; }
.receipt-line small { display: block; margin-top: 2px; color: var(--muted); }
.receipt-total { padding: 18px 0 4px; display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; }
.receipt-total strong { color: var(--orange); font-family: Georgia, serif; font-size: 28px; }
.receipt-actions { padding: 14px 28px 28px; display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.receipt-actions .receipt-close { grid-column: 1 / -1; margin-top: 0; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 340px; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
  .topbar { height: 70px; }
  .brand small { display: none; }
  .hero { grid-template-columns: 1fr; padding-top: 45px; gap: 30px; }
  .workspace { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .search { width: 100%; }
}

@media (max-width: 470px) {
  main { padding-inline: 14px; }
  .topbar { padding-inline: 15px; }
  .ghost-button { padding: 9px 10px; font-size: 11px; }
  .top-actions { gap: 5px; }
  .top-actions .ghost-button { padding-inline: 7px; font-size: 10px; }
  .brand strong { font-size: 13px; }
  .brand-mark { width: 36px; height: 36px; }
  h1 { font-size: 43px; }
  .product-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .product-card { min-height: 178px; padding: 14px; }
  .catalog-panel { padding: 18px 13px; }
  .monthly-stats { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden; }
  #receiptDialog, #receiptDialog * { visibility: visible; }
  #receiptDialog { position: absolute; inset: 0; width: 100%; box-shadow: none; }
  .receipt-actions { display: none; }
}
