:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-strong: #f0efec;
  --text: #22211f;
  --muted: #76716a;
  --line: #e3dfd8;
  --accent: #111111;
  --danger: #b42318;
  --shadow: 0 14px 36px rgba(31, 29, 25, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 840px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(92px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.icon-button,
.primary-button,
.text-button,
.danger-button,
.copy-actions button,
.chip,
.tab {
  border: 0;
  border-radius: 999px;
  min-height: 44px;
}

.icon-button {
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: white;
  font-size: 30px;
  line-height: 1;
}

.icon-button.ghost {
  background: var(--surface-strong);
  color: var(--text);
  font-size: 24px;
}

.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.text-button {
  padding: 0 14px;
  background: var(--surface-strong);
  color: var(--text);
}

.text-button.wide {
  width: 100%;
  margin-top: 12px;
}

.danger-button.wide {
  width: 100%;
}

.danger-button {
  padding: 0 16px;
  background: #fff1ef;
  color: var(--danger);
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stats-grid article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stats-grid span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.stats-grid small {
  color: var(--muted);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--surface-strong);
}

.tab {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.search-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #111111;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 10px;
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.chip {
  flex: 0 0 auto;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}

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

.product-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  box-shadow: none;
}

.product-card img,
.image-fallback {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-strong);
}

.image-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.product-card-body {
  padding: 10px;
}

.product-card h3 {
  display: -webkit-box;
  min-height: 42px;
  margin: 0 0 6px;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.meta,
.keyword-line {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.keyword-line {
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.store-list {
  display: grid;
  gap: 10px;
}

.store-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.store-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.store-card h3 {
  margin-bottom: 4px;
  font-size: 17px;
}

.store-card a {
  color: var(--text);
  word-break: break-all;
}

.store-card p {
  margin: 10px 0 0;
  color: var(--muted);
  white-space: pre-wrap;
}

.empty-state {
  display: none;
  place-items: center;
  gap: 6px;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
}

.empty-state.is-visible {
  display: grid;
}

dialog {
  width: min(100% - 24px, 560px);
  max-height: min(88vh, 760px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.sheet-form,
.detail-sheet {
  padding: 16px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.sheet-form label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.image-preview {
  display: grid;
  place-items: center;
  min-height: 120px;
  margin: -2px 0 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

.form-actions button {
  flex: 1;
}

.detail-image {
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--surface-strong);
}

.detail-sheet h3 {
  margin: 14px 0;
  font-size: 21px;
  line-height: 1.4;
  white-space: pre-wrap;
}

dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

dl div {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dd {
  margin: 4px 0 0;
  white-space: pre-wrap;
}

.copy-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.copy-actions button {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  width: min(100%, 390px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin-bottom: 18px;
  font-size: 24px;
}

.auth-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-card .primary-button {
  width: 100%;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%) translateY(24px);
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 999px;
  background: #111111;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 680px) {
  .app-shell {
    padding-top: 28px;
  }

  .search-panel {
    grid-template-columns: 1.5fr 1fr 1fr;
  }

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

  .copy-actions {
    grid-template-columns: repeat(3, 1fr);
  }
}
