:root {
  --fg: #1a1a1a;
  --fg-muted: #6b7280;
  --bg: #fafaf7;
  --bg-card: #ffffff;
  --border: #e5e5e0;
  --accent: #16a34a;
  --best-bg: #ecfdf5;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 2rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  max-width: 980px;
  margin-inline: auto;
  line-height: 1.5;
}
header h1 { margin: 0 0 .25rem 0; font-size: 1.6rem; }
.muted { color: var(--fg-muted); font-size: .9rem; }
form { margin: 1.5rem 0; }
textarea {
  width: 100%;
  font: inherit;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  resize: vertical;
}
button {
  margin-top: .75rem;
  padding: .6rem 1.2rem;
  font: inherit;
  font-weight: 600;
  color: white;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
.htmx-indicator { display: none; margin-left: .75rem; color: var(--fg-muted); }
.htmx-request .htmx-indicator { display: inline; }
.ingredient { margin: 2rem 0; }
.ingredient h2 { margin: 0 0 .5rem 0; font-size: 1.15rem; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: .55rem .8rem;
  border-bottom: 1px solid var(--border);
  font-size: .92rem;
}
th { background: #f4f4ee; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.best { background: var(--best-bg); font-weight: 600; }
.empty { color: var(--fg-muted); font-style: italic; }
.basket { margin-top: 2.5rem; padding-top: 1rem; border-top: 2px dashed var(--border); }
details { margin-top: .75rem; }
details summary { cursor: pointer; }


.basket-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-height: 50vh;
  overflow-y: auto;
  background: white;
  border-top: 3px solid var(--accent);
  padding: 1rem 1.5rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 100;
}
.basket-panel:empty { display: none; }
body.has-basket { padding-bottom: 40vh; }
.basket-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 0.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.basket-grand { font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.basket-store { margin: 0.5rem 0 0.75rem; }
.basket-store-header {
  display: flex; justify-content: space-between;
  font-size: 0.95rem; padding-bottom: 0.25rem;
}
.basket-panel ul { list-style: none; padding: 0; margin: 0.25rem 0; }
.basket-panel li {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 0.75rem;
  font-size: 0.88rem;
  padding: 0.2rem 0;
}
.basket-ing { color: var(--fg-muted); }
.basket-name { color: var(--fg); }
.basket-price { font-weight: 600; text-align: right; white-space: nowrap; }
input.basket-check { width: 18px; height: 18px; cursor: pointer; }
.open-link { font-size: 0.85rem; color: var(--accent); text-decoration: none; white-space: nowrap; }
.open-link:hover { text-decoration: underline; }


.spinner-dot {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-request .htmx-indicator { display: inline-flex; align-items: center; gap: 0.5rem; }
.htmx-request button[type="submit"] { opacity: 0.5; pointer-events: none; }

@media (max-width: 700px) {
  body { padding: 1rem; }
  header h1 { font-size: 1.3rem; }
  textarea { font-size: 0.95rem; }
  th, td { padding: 0.35rem 0.4rem; font-size: 0.82rem; }
  .updated-col { display: none; }
  .ingredient h2 { font-size: 1rem; }
  .basket-panel { padding: 0.75rem 1rem; max-height: 60vh; }
  .basket-panel li {
    grid-template-columns: 1fr auto;
    gap: 0.25rem 0.5rem;
  }
  .basket-ing { font-size: 0.75rem; grid-column: 1 / -1; }
  .basket-grand { font-size: 1.2rem; }
  input.basket-check { width: 22px; height: 22px; }
  .open-link { padding: 0.25rem; }
}


/* Collapsed basket pill (default state when items selected) */
.basket-panel.collapsed {
  position: fixed; bottom: 1rem; right: 1rem;
  max-width: 280px; background: white; padding: 0;
  border-radius: 999px; border: 2px solid var(--accent);
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  border-top: 2px solid var(--accent);  /* override inherited */
}
.basket-pill {
  font: inherit; font-size: 1rem; font-weight: 700;
  color: var(--fg); background: transparent; border: 0;
  padding: 0.7rem 1.4rem; cursor: pointer; border-radius: 999px;
}
.basket-pill:hover { background: var(--best-bg); }

/* Expanded panel only takes space when expanded */
body.basket-collapsed { padding-bottom: 0; }
body.basket-expanded { padding-bottom: 50vh; }
.basket-panel.expanded { display: block; }
.basket-meta { display: block; color: var(--fg-muted); font-size: 0.78rem; margin-top: 0.1rem; }

/* Show more button */
.show-more {
  display: block; margin: 0.5rem auto 1rem; padding: 0.4rem 1rem;
  background: white; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; cursor: pointer; font: inherit; font-size: 0.85rem;
}
.show-more:hover { background: var(--best-bg); }
.row-hidden { display: none; }

/* ── v2: confidence badges + recipe basket ───────────────────────────── */
.small { font-size: .82rem; }
code { background: rgba(0,0,0,.05); padding: .05rem .3rem; border-radius: 3px; font-size: .9em; }

.recipe-summary { margin: 1rem 0; padding: .75rem 1rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; }
.recipe-summary h2 { margin: 0 0 .5rem 0; font-size: 1.05rem; }
.recipe-lines { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
.recipe-lines li { font-size: .9rem; }
.recipe-ing { font-weight: 600; }
.recipe-qty { color: var(--fg-muted); margin-left: .25rem; font-size: .85rem; }

.baskets { margin: 1.5rem 0; }
.baskets h2 { margin: 0 0 .25rem 0; font-size: 1.15rem; }
.basket-card {
  margin: .5rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  overflow: hidden;
}
.basket-card.best { border-color: var(--accent); background: var(--best-bg); }
.basket-card > summary {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: .65rem 1rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}
.basket-card > summary::-webkit-details-marker { display: none; }
.basket-store { flex: 1; }
.basket-coverage { color: var(--fg-muted); font-weight: normal; font-size: .9rem; }
.basket-total { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.best-badge {
  display: inline-block; margin-right: .5rem; padding: .1rem .5rem;
  background: var(--accent); color: white; border-radius: 999px;
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; vertical-align: middle;
}
.basket-table { margin: 0; border-top: 1px solid var(--border); }
.basket-table th, .basket-table td { padding: .4rem .8rem; font-size: .9rem; }
.basket-table th { background: rgba(0,0,0,.02); text-align: left; font-weight: 600; }
.basket-table tr.missing td { color: var(--fg-muted); font-style: italic; }

.ingredients-header { margin-top: 2rem; font-size: 1.15rem; }
.rank-table th, .rank-table td { padding: .35rem .5rem; }

/* Confidence badges */
.badge {
  display: inline-block; margin-left: .35rem; padding: .05rem .35rem;
  border-radius: 4px; font-size: .65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
  vertical-align: middle; line-height: 1.4;
}
.badge-exact     { background: #dcfce7; color: #14532d; }   /* green = authoritative */
.badge-computed  { background: #e0e7ff; color: #1e3a8a; }   /* blue = derived */
.badge-estimated { background: #fef3c7; color: #78350f; }   /* amber = estimated */
.badge-piece     { background: #f3f4f6; color: #4b5563; }   /* gray = best-effort */
.badge-est       { background: #fef3c7; color: #78350f; }   /* amber = price estimate */

.unparseable-section { margin: .5rem 0 0 0; }
.unparseable-section table { border: 1px dashed var(--border); }

@media (max-width: 700px) {
  body { padding: 1rem; }
  .basket-card > summary { flex-wrap: wrap; }
  .basket-table th, .basket-table td { font-size: .8rem; padding: .3rem .4rem; }
  .updated-col { display: none; }
}
