:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #9aa8bc;
  --accent: #3d9a6a;
  --accent-hover: #48b37c;
  --border: #2a3a4f;
  --danger: #e85d5d;
  font-family: "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1a2332;
    --muted: #5c6b7a;
    --border: #d0d7e0;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.45;
  background-color: var(--bg);
  /* Illustration lives on a fixed layer so it stays visible and scrolls cleanly */
  position: relative;
}

/* Split grocery panels (left + right) so art stays on the edges at any width.
   Assets: public/grocery-value-bg-left.svg, public/grocery-value-bg-right.svg */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: var(--bg);
  background-image:
    url("/grocery-value-bg-left.svg"),
    url("/grocery-value-bg-right.svg");
  background-repeat: no-repeat, no-repeat;
  /* Scale with viewport height; cap width so the centre stays clear for content */
  background-size:
    min(42vw, 28rem) 100%,
    min(42vw, 28rem) 100%;
  background-position: left center, right center;
  opacity: 1;
}

/* Narrow screens: keep panels present but smaller so they frame rather than dominate */
@media (max-width: 40rem) {
  body::before {
    background-size:
      min(48vw, 12rem) 100%,
      min(48vw, 12rem) 100%;
  }
}

/* Very wide screens: allow a bit more side art without covering the content column */
@media (min-width: 80rem) {
  body::before {
    background-size:
      min(36vw, 32rem) 100%,
      min(36vw, 32rem) 100%;
  }
}

/* Light scrim so text contrast stays OK without hiding the art */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: color-mix(in srgb, var(--bg) 35%, transparent);
}

@supports not (background: color-mix(in srgb, #000 50%, transparent)) {
  body::after {
    background: rgba(15, 20, 25, 0.35);
  }
  @media (prefers-color-scheme: light) {
    body::after {
      background: rgba(244, 246, 248, 0.35);
    }
  }
}

.wrap {
  max-width: 32rem;
  margin: 0 auto;
  padding: 1.25rem;
  position: relative;
  z-index: 1;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

.sub {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Form surfaces: 30% opaque so veg/fruit background shows through */
.card {
  background: color-mix(in srgb, var(--card) 30%, transparent);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.25rem;
  margin-bottom: 1rem;
}

input,
select,
textarea,
.geo,
.progressive-block,
.result,
.vision-proposal {
  background: color-mix(in srgb, var(--bg) 30%, transparent) !important;
  backdrop-filter: blur(3px);
}

@supports not (background: color-mix(in srgb, #000 50%, transparent)) {
  .card {
    background: rgba(26, 35, 50, 0.3);
  }
  @media (prefers-color-scheme: light) {
    .card {
      background: rgba(255, 255, 255, 0.3);
    }
  }
  input,
  select,
  textarea,
  .geo,
  .progressive-block,
  .result,
  .vision-proposal {
    background: rgba(15, 20, 25, 0.3) !important;
  }
  @media (prefers-color-scheme: light) {
    input,
    select,
    textarea,
    .geo,
    .progressive-block,
    .result,
    .vision-proposal {
      background: rgba(255, 255, 255, 0.3) !important;
    }
  }
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

input,
select {
  font: inherit;
  font-weight: 400;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  /* opacity set with form surfaces above */
  color: var(--text);
}

input:read-only {
  opacity: 0.9;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.geo {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin: 0.5rem 0 1rem;
}

.geo legend {
  padding: 0 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}

button {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  width: 100%;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

button.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8rem;
  font-weight: 400;
}

.result {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.recent {
  font-size: 0.85rem;
}

.recent table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}

.recent th,
.recent td {
  text-align: left;
  padding: 0.4rem 0.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 400;
}

.recent th {
  color: var(--muted);
  font-size: 0.75rem;
}

.error {
  color: var(--danger);
}

.session-bar {
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

/* Progressive disclosure: catalog + geo coords */
.progressive-block {
  margin-bottom: 0.85rem;
  padding: 0.75rem 0.85rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  /* background: 30% opaque — see form surfaces above */
}

.catalog-wizard-visible {
  /* Always painted — category lives here */
  display: block;
}

.form-section-title {
  margin: 0 0 0.65rem;
  font-size: 1rem;
  font-weight: 700;
}

.progressive-intro {
  margin: 0 0 0.5rem;
}

.form-step {
  margin-top: 0.35rem;
}

#step-category {
  /* Never collapse the primary category control */
  display: block !important;
}

.more-line {
  margin: 0.15rem 0 0.65rem;
  font-weight: 400;
}

a.more-link {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

a.more-link:hover {
  color: var(--accent-hover);
}

/*
 * Training / help copy — hidden for expert mode (default).
 * Future: document.body.classList.add("training-mode") to reveal all .training.
 */
.training {
  display: none !important;
}

body.training-mode .training {
  display: revert !important;
}

body.training-mode p.training,
body.training-mode .sub.training {
  display: block !important;
}

body.training-mode span.training {
  display: inline !important;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.auth-tabs .tab.active {
  border-color: var(--accent);
  color: var(--accent);
}

.auth-form {
  margin-top: 0.5rem;
}

.auth-form #auth-cancel {
  margin-top: 0.5rem;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  padding: 2px;
}

.recent-line-head {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}

.recent-line-body {
  flex: 1;
  min-width: 0;
}

.obs-thumb-cell {
  width: 52px;
  vertical-align: middle;
}

.photo-preview {
  display: block;
  max-width: 100%;
  max-height: 200px;
  margin-top: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#auth-msg {
  margin-top: 0.75rem;
}

#logout-btn {
  margin-top: 0.5rem;
}

.profile-panel {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.profile-form {
  margin-top: 0.75rem;
}

.profile-form #profile-cancel-btn {
  margin-top: 0.5rem;
}

#profile-edit-btn {
  margin-top: 0.35rem;
}

.suggest-panel {
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.suggest-panel summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.suggestion-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.suggestion-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.suggestion-actions button {
  width: 100%;
}

#attrs-fields label {
  margin-bottom: 0.6rem;
}

select[multiple] {
  min-height: 4.5rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  appearance: none;
  width: auto;
  margin: 0;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.chip.facet {
  font-weight: 400;
  opacity: 0.95;
}

.chip.product-name {
  font-weight: 600;
}

.recent-lines {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.recent-line {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}

.recent-line-meta {
  font-size: 0.75rem;
}

#facet-selection-status {
  margin: 0 0 0.65rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

#clear-facets-btn {
  margin-top: 0.65rem;
}

.chip.facet:focus-visible,
.chip.product-name:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vision-proposal {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.85rem;
}

.vision-proposal h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.vision-proposal pre {
  margin: 0.5rem 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
}

.vision-proposal .match-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.5rem 0;
}

.vision-proposal .match-list button {
  width: 100%;
  text-align: left;
  font-weight: 500;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.vision-proposal .match-list button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#vision-btn {
  margin-top: 0.5rem;
}

.store-map {
  width: 100%;
  height: 260px;
  min-height: 260px;
  margin: 0.5rem 0 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  z-index: 0;
  background: var(--bg);
  /* Ensure layout size even before Leaflet paints (avoids 0×0 init) */
  position: relative;
}

.store-map .leaflet-popup-content {
  margin: 0.5rem 0.65rem;
  font-size: 0.85rem;
  line-height: 1.35;
}

.store-map .leaflet-popup-content strong {
  display: block;
  margin-bottom: 0.15rem;
}

/* bg-layer-v3 1785254093 */
/* form-opacity-30 1785254432 */

/* opacity-30-deploy 1785254483 */
/* redeploy-1785254537 */
