/* ═══════════════════════════════════════════════════════════
   Produce Explorer — app.css
   Theme tokens borrowed from Simplista Transit (main.css /
   components.css). Explorer-specific layout and components
   are defined below the token block.
   ═══════════════════════════════════════════════════════════ */

/* ── Light theme tokens (default) ───────────────────────── */
:root {
  --color-primary:       #2563eb;
  --color-primary-dark:  #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-success:       #22c55e;
  --color-success-light: #dcfce7;
  --color-success-text:  #15803d;
  --color-error:         #ef4444;
  --color-bg:            #f8fafc;
  --color-surface:       #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-border:        #e2e8f0;
  --color-text:          #1e293b;
  --color-text-muted:    #64748b;
  --color-text-light:    #94a3b8;

  --header-bg:              #1e293b;
  --header-border:          #0f172a;
  --header-text:            #e2e8f0;
  --header-muted:           #94a3b8;

  --font-family:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-base: 14px;
  --font-size-sm:   12px;
  --font-size-lg:   16px;

  --header-height: 56px;
  --toolbar-height: 96px;
  --card-radius:   8px;
  --card-shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --border-radius: 6px;
}

/* ── Dark theme tokens ───────────────────────────────────── */
[data-theme="dark"] {
  --color-primary:       #3b82f6;
  --color-primary-dark:  #60a5fa;
  --color-primary-light: rgba(59,130,246,0.18);
  --color-success:       #4ade80;
  --color-success-light: rgba(74,222,128,0.15);
  --color-success-text:  #86efac;
  --color-error:         #f87171;
  --color-bg:            #0f172a;
  --color-surface:       #1e293b;
  --color-surface-hover: rgba(255,255,255,0.05);
  --color-border:        #334155;
  --color-text:          #f1f5f9;
  --color-text-muted:    #94a3b8;
  --color-text-light:    #475569;
  --card-shadow:         0 1px 4px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);

  --header-bg:     #020617;
  --header-border: #1e293b;
}

/* ── Reset + base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: var(--font-size-base); }

body {
  font-family:      var(--font-family);
  font-size:        var(--font-size-base);
  background-color: var(--color-bg);
  color:            var(--color-text);
  line-height:      1.5;
  padding-top:      calc(var(--header-height) + var(--toolbar-height));
}

/* ── Header ──────────────────────────────────────────────── */
#app-header {
  position:      fixed;
  top:           0;
  left:          0;
  right:         0;
  height:        var(--header-height);
  background:    var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  z-index:       100;
  box-shadow:    0 2px 8px rgba(0,0,0,.22);
}

.header-inner {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  height:          100%;
  padding:         0 24px;
  gap:             16px;
}

.brand {
  display:     flex;
  align-items: center;
  gap:         8px;
  flex-shrink: 0;
}
.brand-icon { font-size: 22px; }
.brand-name {
  font-weight:    700;
  font-size:      1.1rem;
  letter-spacing: -.5px;
  color:          #ffffff;
}

.result-count {
  font-size:  var(--font-size-sm);
  color:      var(--header-muted);
  flex:       1;
  text-align: center;
}

.theme-toggle-btn {
  width:           32px;
  height:          32px;
  padding:         0;
  border:          1px solid rgba(255,255,255,0.15);
  border-radius:   var(--border-radius);
  background:      rgba(255,255,255,0.07);
  color:           var(--header-text);
  cursor:          pointer;
  font-size:       15px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  transition:      background .15s, border-color .15s;
  flex-shrink:     0;
}
.theme-toggle-btn:hover {
  background:   rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.28);
}

/* ── Toolbar ─────────────────────────────────────────────── */
#toolbar {
  position:      fixed;
  top:           var(--header-height);
  left:          0;
  right:         0;
  height:        var(--toolbar-height);
  background:    var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index:       90;
  padding:       10px 24px;
  display:       flex;
  flex-direction: column;
  justify-content: center;
  gap:           8px;
}

.toolbar-inner {
  display:        flex;
  flex-direction: column;
  gap:            8px;
  max-width:      100%;
}

/* ── Search input ────────────────────────────────────────── */
.search-wrap {
  position:    relative;
  display:     flex;
  align-items: center;
}

.search-icon {
  position:    absolute;
  left:        10px;
  color:       var(--color-text-muted);
  font-size:   16px;
  line-height: 1;
  pointer-events: none;
}

.search-input {
  width:         100%;
  padding:       8px 36px 8px 32px;
  border:        1px solid var(--color-border);
  border-radius: var(--border-radius);
  background:    var(--color-surface);
  color:         var(--color-text);
  font-size:     var(--font-size-base);
  font-family:   var(--font-family);
  transition:    border-color .15s, box-shadow .15s;
  outline:       none;
}
.search-input::placeholder { color: var(--color-text-light); }
.search-input:focus {
  border-color: var(--color-primary);
  box-shadow:   0 0 0 3px var(--color-primary-light);
}

.clear-btn {
  position:    absolute;
  right:       8px;
  background:  none;
  border:      none;
  color:       var(--color-text-muted);
  cursor:      pointer;
  font-size:   13px;
  line-height: 1;
  padding:     4px;
  border-radius: 50%;
  transition:  color .12s, background .12s;
}
.clear-btn:hover { color: var(--color-text); background: var(--color-surface-hover); }

/* ── Filter row ──────────────────────────────────────────── */
.filter-row {
  display:     flex;
  align-items: center;
  gap:         8px;
  flex-wrap:   wrap;
}

.chip-group {
  display:     flex;
  align-items: center;
  gap:         4px;
  flex-wrap:   wrap;
}

.filter-divider {
  width:      1px;
  height:     20px;
  background: var(--color-border);
  flex-shrink: 0;
}

/* ── Chips ───────────────────────────────────────────────── */
.chip {
  padding:       4px 12px;
  border:        1px solid var(--color-border);
  border-radius: 20px;
  background:    var(--color-surface);
  color:         var(--color-text-muted);
  font-size:     var(--font-size-sm);
  font-weight:   500;
  font-family:   var(--font-family);
  cursor:        pointer;
  transition:    background .12s, border-color .12s, color .12s;
  white-space:   nowrap;
}
.chip:hover {
  background:   var(--color-surface-hover);
  color:        var(--color-text);
  border-color: var(--color-text-light);
}
.chip.active {
  background:   var(--color-primary-light);
  border-color: var(--color-primary);
  color:        var(--color-primary);
  font-weight:  600;
}

/* ── Retailer-assigned toggle ────────────────────────────── */
.retailer-toggle {
  font-style: italic;
  opacity:    0.6;
}
.retailer-toggle:hover {
  opacity: 1;
}
.retailer-toggle.active {
  opacity:      1;
  font-style:   normal;
}

/* ── Produce grid ────────────────────────────────────────── */
#grid-container {
  padding: 20px 24px 32px;
}

.produce-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap:                   16px;
}

/* ── Produce card ────────────────────────────────────────── */
.produce-card {
  background:    var(--color-surface);
  border:        1px solid var(--color-border);
  border-radius: var(--card-radius);
  overflow:      hidden;
  cursor:        pointer;
  box-shadow:    var(--card-shadow);
  transition:    transform .15s ease, box-shadow .15s ease, border-color .15s;
  outline:       none;
}
.produce-card:hover,
.produce-card:focus-visible {
  transform:    translateY(-4px);
  box-shadow:   0 8px 24px rgba(0,0,0,.13);
  border-color: var(--color-primary);
}
[data-theme="dark"] .produce-card:hover,
[data-theme="dark"] .produce-card:focus-visible {
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}

.card-image-wrap {
  position:     relative;
  aspect-ratio: 1;
  overflow:     hidden;
  background:   #ffffff; /* always white — matches generated image bg */
}

.card-image-wrap img {
  width:       100%;
  height:      100%;
  object-fit:  cover;
  display:     block;
  transition:  transform .2s ease;
}
.produce-card:hover .card-image-wrap img { transform: scale(1.04); }

.card-image-placeholder {
  width:            100%;
  height:           100%;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        3.5rem;
  color:            var(--color-text-light);
  background:       var(--color-surface-hover);
}

.organic-badge {
  position:      absolute;
  top:           8px;
  right:         8px;
  background:    rgba(22, 163, 74, 0.9);
  color:         #fff;
  font-size:     10px;
  font-weight:   700;
  padding:       3px 7px;
  border-radius: 10px;
  letter-spacing: .03em;
  backdrop-filter: blur(2px);
}

.card-body {
  padding: 10px 12px 13px;
}

.plu-badge {
  display:       inline-block;
  background:    var(--color-primary-light);
  color:         var(--color-primary);
  font-size:     10px;
  font-weight:   700;
  padding:       2px 8px;
  border-radius: 10px;
  font-family:   monospace;
  letter-spacing: .04em;
}

.card-title {
  font-size:     0.875rem;
  font-weight:   600;
  color:         var(--color-text);
  margin:        6px 0 4px;
  white-space:   nowrap;
  overflow:      hidden;
  text-overflow: ellipsis;
}

.card-short-desc {
  font-size:            0.75rem;
  color:                var(--color-text-muted);
  line-height:          1.45;
  display:              -webkit-box;
  -webkit-line-clamp:   2;
  -webkit-box-orient:   vertical;
  overflow:             hidden;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  gap:             12px;
  padding:         80px 24px;
  text-align:      center;
}
.empty-icon { font-size: 3rem; }
.empty-text { color: var(--color-text-muted); font-size: var(--font-size-lg); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display:         inline-flex;
  align-items:     center;
  gap:             6px;
  padding:         8px 16px;
  border:          1px solid transparent;
  border-radius:   var(--border-radius);
  font-size:       var(--font-size-base);
  font-family:     var(--font-family);
  font-weight:     500;
  cursor:          pointer;
  transition:      background .15s, border-color .15s, color .15s;
  text-decoration: none;
  white-space:     nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-outline {
  background:   transparent;
  border-color: var(--color-border);
  color:        var(--color-text);
}
.btn-outline:hover:not(:disabled) {
  background:   var(--color-surface-hover);
  border-color: var(--color-text-light);
}

.btn-sm { padding: 4px 10px; font-size: var(--font-size-sm); }

/* ── Modal overlay ───────────────────────────────────────── */
.modal-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(0,0,0,.6);
  z-index:         200;
  display:         flex;
  align-items:     center;
  justify-content: center;
  padding:         24px;
  animation:       overlayIn .15s ease;
}
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.75); }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Modal ───────────────────────────────────────────────── */
.modal {
  background:    var(--color-surface);
  border:        1px solid var(--color-border);
  border-radius: calc(var(--card-radius) * 1.5);
  width:         100%;
  max-width:     900px;
  max-height:    calc(100vh - 48px);
  overflow-y:    auto;
  position:      relative;
  box-shadow:    0 24px 64px rgba(0,0,0,.28);
  animation:     modalIn .2s ease;
}
[data-theme="dark"] .modal { box-shadow: 0 24px 64px rgba(0,0,0,.65); }

@keyframes modalIn {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-close-btn {
  position:      absolute;
  top:           14px;
  right:         14px;
  width:         30px;
  height:        30px;
  border:        1px solid var(--color-border);
  border-radius: 50%;
  background:    var(--color-surface-hover);
  color:         var(--color-text-muted);
  font-size:     13px;
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    background .12s, color .12s;
  z-index:       1;
}
.modal-close-btn:hover { background: var(--color-error); color: #fff; border-color: transparent; }

.modal-body {
  display: flex;
  gap:     0;
}

/* ── Modal — image column ────────────────────────────────── */
.modal-image-col {
  flex:        0 0 42%;
  background:  #ffffff;
  border-right: 1px solid var(--color-border);
  border-radius: calc(var(--card-radius) * 1.5) 0 0 calc(var(--card-radius) * 1.5);
  overflow:    hidden;
  display:     flex;
  align-items: center;
  justify-content: center;
}

.modal-image-wrap {
  width:  100%;
  aspect-ratio: 1;
  position: relative;
}

.modal-image-wrap img {
  width:      100%;
  height:     100%;
  object-fit: contain;
  display:    block;
}

.modal-placeholder {
  position:        absolute;
  inset:           0;
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       5rem;
  color:           var(--color-text-light);
}

/* ── Modal — detail column ───────────────────────────────── */
.modal-detail-col {
  flex:    1;
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  gap:     14px;
  min-width: 0;
}

.modal-product-title {
  font-size:   1.4rem;
  font-weight: 700;
  color:       var(--color-text);
  line-height: 1.2;
}

.modal-badge-row {
  display:     flex;
  align-items: center;
  gap:         8px;
  flex-wrap:   wrap;
}

.modal-plu-badge {
  display:       inline-block;
  background:    var(--color-primary-light);
  color:         var(--color-primary);
  font-size:     12px;
  font-weight:   700;
  padding:       3px 10px;
  border-radius: 10px;
  font-family:   monospace;
  letter-spacing: .04em;
}

.modal-organic-badge {
  display:       inline-block;
  background:    rgba(22,163,74,.12);
  color:         #16a34a;
  font-size:     12px;
  font-weight:   600;
  padding:       3px 10px;
  border-radius: 10px;
}
[data-theme="dark"] .modal-organic-badge { color: #4ade80; background: rgba(74,222,128,.12); }

.modal-standard-badge {
  display:       inline-block;
  background:    var(--color-surface-hover);
  color:         var(--color-text-muted);
  font-size:     12px;
  font-weight:   600;
  padding:       3px 10px;
  border-radius: 10px;
  border:        1px solid var(--color-border);
}

.modal-short-desc {
  font-size:   1rem;
  font-weight: 500;
  color:       var(--color-text);
  line-height: 1.5;
}

.modal-desc {
  font-size:   0.875rem;
  color:       var(--color-text-muted);
  line-height: 1.6;
}

/* ── Detail table ────────────────────────────────────────── */
.detail-table {
  width:           100%;
  border-collapse: collapse;
  font-size:       var(--font-size-sm);
}
.detail-table th,
.detail-table td {
  padding:     6px 10px;
  text-align:  left;
  border-bottom: 1px solid var(--color-border);
}
.detail-table th {
  width:       36%;
  color:       var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.detail-table td {
  color:        var(--color-text);
  font-weight:  400;
  word-break:   break-all;
}
.detail-table tr:last-child th,
.detail-table tr:last-child td { border-bottom: none; }

/* ── Restrictions note ───────────────────────────────────── */
.modal-restrictions {
  font-size:    var(--font-size-sm);
  color:        var(--color-text-muted);
  line-height:  1.5;
  padding:      10px 12px;
  border-left:  3px solid var(--color-primary);
  background:   var(--color-primary-light);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
}
[data-theme="dark"] .modal-restrictions {
  background: rgba(59,130,246,0.1);
}

/* ── Modal URL row ───────────────────────────────────────── */
.modal-url-row {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     10px 0 0;
  border-top:  1px solid var(--color-border);
  flex-wrap:   wrap;
}

.url-link {
  font-size:     var(--font-size-sm);
  color:         var(--color-primary);
  text-overflow: ellipsis;
  overflow:      hidden;
  white-space:   nowrap;
  max-width:     340px;
  flex:          1;
  min-width:     0;
}
.url-link:hover { text-decoration: underline; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  flex-wrap:       wrap;
  gap:             12px;
  padding:         16px 0 8px;
  border-top:      1px solid var(--color-border);
  margin-top:      8px;
}

.page-info {
  font-size:  var(--font-size-sm);
  color:      var(--color-text-muted);
  white-space: nowrap;
}

.page-buttons {
  display:     flex;
  align-items: center;
  gap:         4px;
  flex-wrap:   wrap;
}

.page-btn {
  min-width:     34px;
  height:        34px;
  padding:       0 8px;
  border:        1px solid var(--color-border);
  border-radius: var(--border-radius);
  background:    var(--color-surface);
  color:         var(--color-text);
  font-size:     var(--font-size-sm);
  font-family:   var(--font-family);
  font-weight:   500;
  cursor:        pointer;
  transition:    background .12s, border-color .12s, color .12s;
  line-height:   1;
}
.page-btn:hover:not(:disabled):not(.active) {
  background:   var(--color-surface-hover);
  border-color: var(--color-text-light);
}
.page-btn.active {
  background:   var(--color-primary);
  border-color: var(--color-primary);
  color:        #fff;
  font-weight:  600;
}
.page-btn:disabled {
  opacity: .35;
  cursor:  not-allowed;
}

.page-ellipsis {
  min-width:   24px;
  text-align:  center;
  color:       var(--color-text-muted);
  font-size:   var(--font-size-sm);
  user-select: none;
}

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 680px) {
  :root { --toolbar-height: 116px; }

  .modal-body {
    flex-direction: column;
  }
  .modal-image-col {
    flex:        0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    border-radius: calc(var(--card-radius) * 1.5) calc(var(--card-radius) * 1.5) 0 0;
  }
  .modal-image-wrap { aspect-ratio: 1; max-height: 280px; }
  .modal-detail-col { padding: 20px; }

  .produce-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

  #grid-container { padding: 14px 14px 28px; }
  #toolbar        { padding: 10px 14px; }
}
