:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --line: #e3e7ec;
  --brand: #2f6fed;
  --brand-ink: #ffffff;
  --danger-bg: #fdecec;
  --danger-ink: #b3261e;
  --ok-bg: #eaf6ee;
  --ok-ink: #1f7a3d;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; }

.nav { display: flex; align-items: center; gap: 18px; }
.nav a { color: var(--brand); text-decoration: none; font-weight: 500; }
.inline { margin: 0; display: inline; }
.linklike {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font: inherit; padding: 0;
}
.linklike:hover { color: var(--ink); }

.container { max-width: 1080px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
h1 { font-size: 22px; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 520px;
}
.auth-card { margin: 8vh auto 0; }

label { display: block; margin-bottom: 14px; font-weight: 500; font-size: 14px; }
input {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 15px;
}
input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.btn {
  display: inline-block; background: var(--brand); color: var(--brand-ink);
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 15px;
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.actions { display: flex; gap: 10px; align-items: center; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.flashes { margin-bottom: 18px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.flash-error { background: var(--danger-bg); color: var(--danger-ink); }
.flash-success { background: var(--ok-bg); color: var(--ok-ink); }

/* Status filter chips */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 20px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
  font-size: 13px; font-weight: 600; text-transform: capitalize;
}
.chip:hover { border-color: var(--brand); }
.chip-active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip-count {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: #eef1f5; border-radius: 999px; padding: 1px 7px; min-width: 20px;
  text-align: center;
}
.chip-active .chip-count { background: rgba(255, 255, 255, .25); color: var(--brand-ink); }

/* Bottom stats bar */
.statsbar {
  position: sticky; bottom: 16px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  margin-top: 28px;
  background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(28, 36, 48, .08);
}
.stat { background: var(--card); padding: 12px 16px; text-align: center; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-total { font-size: 20px; font-weight: 700; margin: 4px 0 2px; }
.stat-count { font-size: 12px; color: var(--muted); }

@media (max-width: 520px) {
  .statsbar { grid-template-columns: repeat(2, 1fr); }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
}
.product {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; text-decoration: none;
  color: inherit; display: flex; flex-direction: column;
}
.linkcard:hover { border-color: var(--brand); }
.tile-date {
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.tile-date.date-stale { color: #d33; }
.thumb {
  aspect-ratio: 1 / 1; background: #fafbfc;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--line);
  /* As a column flex-item, the thumb's automatic minimum size (min-height:
     auto) is the image's intrinsic height. Chromium (Brave) lets that
     override aspect-ratio for tall/wide images; min-*:0 keeps it square. */
  min-height: 0; min-width: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb-empty { color: var(--muted); font-size: 13px; }
.product-body { padding: 12px 14px; }
.product-title {
  font-size: 14px; line-height: 1.35; margin-bottom: 8px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-price { font-weight: 700; font-size: 16px; }

.empty {
  text-align: center; color: var(--muted); padding: 60px 20px;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .btn { margin-top: 14px; }

/* Status badge on cards */
.badge {
  display: inline-block; margin-top: 10px; padding: 3px 9px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef1f5; color: var(--muted); text-transform: capitalize;
}
.badge-ordered { background: #eaf1ff; color: #2f6fed; }
.badge-received { background: #eaf6ee; color: #1f7a3d; }
.badge-reviewed { background: #f3ecfb; color: #6b3fb3; }
.badge-cancelled { background: #fdecec; color: #b3261e; }

/* Edit / detail page */
.edit-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 24px;
  align-items: start;
}
.edit-image {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.edit-image img { width: 100%; height: auto; object-fit: contain; border-radius: 8px; }
.source-link {
  display: inline-block; margin-top: 12px; font-size: 13px;
  color: var(--brand); text-decoration: none;
}
.edit-form { max-width: none; }
.edit-form textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical;
  line-height: 1.4;
}
.edit-form textarea:focus,
.edit-form select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.edit-form select {
  width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}

.field { margin-bottom: 14px; }
.field-label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 4px; }

/* Pure-CSS star rating. Inputs are visually hidden; labels are the stars.
   The .stars container is reversed so `input:checked ~ label` fills every
   star from the selected one leftward. */
.stars { display: inline-flex; flex-direction: row-reverse; justify-content: flex-end; }
.stars input { position: absolute; opacity: 0; width: 0; height: 0; }
.stars label {
  font-size: 30px; line-height: 1; color: #d4d9e0; cursor: pointer;
  padding: 0 2px; transition: color .1s;
}
.stars label:hover,
.stars label:hover ~ label,
.stars input:checked ~ label { color: #f5a623; }
.stars input:focus-visible + label { outline: 2px solid var(--brand); border-radius: 4px; }

@media (max-width: 640px) {
  .edit-layout { grid-template-columns: 1fr; }
}

/* Ask Amy */
.amy {
  margin: 4px 0 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.amy-bar { display: flex; align-items: center; gap: 12px; }
.amy-spinner { color: var(--muted); font-size: 14px; }
.amy-meta { color: var(--muted); font-size: 13px; margin: 12px 0 6px; }
.amy-response {
  font-size: 15px; line-height: 1.5;
}
.amy-response:empty { display: none; }
.amy-response > *:first-child { margin-top: 0; }
.amy-response h1, .amy-response h2, .amy-response h3 { font-size: 16px; margin: 16px 0 8px; }
.amy-response ul, .amy-response ol { padding-left: 20px; }
.amy-response table { border-collapse: collapse; margin: 10px 0; }
.amy-response th, .amy-response td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.amy-response pre {
  position: relative; background: #f6f8fa; border: 1px solid var(--line);
  border-radius: 8px; padding: 14px 14px 14px; overflow-x: auto;
}
.amy-response pre code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.amy-response code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.amy-error { color: var(--danger-ink); background: var(--danger-bg); padding: 10px 14px; border-radius: 8px; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; width: auto; margin: 0;
}
.copy-btn:hover { color: var(--ink); }

/* Settings page */
.settings-form { max-width: 640px; }
.settings-heading { font-size: 16px; margin: 0 0 4px; }
.settings-note { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.settings-form textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical; line-height: 1.4;
}
.settings-form textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.settings-form textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
}
