/* Food Supplier Finder — Compare surface (dense B2B tool, Jinja2-served)
   Type: IBM Plex Sans (UI), IBM Plex Mono (numbers, ids, codes)
   Palette: warm paper neutrals + one deep green accent. No tech-gradient,
   no indigo default. Amber = "approximate", red = "unavailable/degraded". */

:root{
  --bg: #f3f1e9;
  --surface: #ffffff;
  --surface-sunken: #eae6d8;
  --ink: #1c1e16;
  --ink-soft: #46473c;
  --ink-muted: #7a7868;
  --border: #d9d3bf;
  --border-strong: #c4bca3;

  --accent: #2c5940;
  --accent-dark: #1f4330;
  --accent-ink: #f4f2ec;
  --accent-soft: #e2ebe3;
  --accent-soft-border: #bfd4c4;

  --amber-bg: #f6ecd2;
  --amber-ink: #7a5412;
  --amber-border: #e3cd96;

  --red-bg: #f7e4de;
  --red-ink: #8a3322;
  --red-border: #e3b6a6;

  --radius-s: 4px;
  --radius-m: 8px;
  --shadow-drawer: -16px 0 32px -16px rgba(28,30,22,0.25);

  --font-ui: 'IBM Plex Sans', -apple-system, Segoe UI, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
}

*{ box-sizing: border-box; }

html,body{
  margin:0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}

h1,h2,h3{ margin:0; font-weight:600; letter-spacing: -0.01em; }

button, input, select, textarea{ font-family: inherit; font-size: inherit; color: inherit; }

:focus-visible{ outline: 2px solid var(--accent); outline-offset: 1px; }

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

/* ---------- topbar ---------- */

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top:0;
  z-index: 20;
}

.topbar__brand{ display:flex; align-items:center; gap:12px; }

.topbar__mark{
  width: 34px; height: 34px;
  display:flex; align-items:center; justify-content:center;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius-s);
  flex: none;
}

.topbar__title h1{ font-size: 16px; }
.topbar__title p{ margin: 2px 0 0; font-size: 12px; color: var(--ink-muted); }

.topbar__meta{ display:flex; align-items:center; gap: 10px; }

.sources{ display:flex; gap:6px; flex-wrap: wrap; }

.source-chip{
  display:flex; align-items:center; gap:6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface);
  white-space: nowrap;
}
.source-chip__dot{ width:7px; height:7px; border-radius: 50%; background: var(--ink-muted); flex:none; }
.source-chip--ok .source-chip__dot{ background: var(--accent); }
.source-chip--down .source-chip__dot{ background: #b5493a; }
.source-chip--down{ color: var(--red-ink); border-color: var(--red-border); background: var(--red-bg); }

.quota{
  display:flex; align-items:center; gap:7px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: default;
}
.quota__dot{ width:7px; height:7px; border-radius:50%; background: var(--accent); flex:none; }
.quota--warn .quota__dot{ background: #b5793a; }
.quota--empty .quota__dot{ background: #b5493a; }

.icon-btn{
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-s);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover{ background: var(--surface-sunken); }

.settings-pop{
  position: absolute;
  top: 58px; right: 24px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  padding: 14px;
  box-shadow: 0 12px 28px -12px rgba(28,30,22,0.3);
  z-index: 30;
}
.settings-pop label{ display:block; font-size:12px; font-weight:600; margin-bottom:6px; }
.settings-pop input{
  width:100%; padding: 8px 10px; border:1px solid var(--border-strong);
  border-radius: var(--radius-s); background: var(--surface-sunken);
}
.settings-pop__hint{ font-size: 11px; color: var(--ink-muted); margin: 8px 0 0; }
.settings-pop__row{ display:flex; justify-content:flex-end; gap:8px; margin-top:12px; }

/* ---------- layout + toolbar ---------- */

.layout{ max-width: 1240px; margin: 0 auto; padding: 20px 24px 48px; }

.howto{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  margin-bottom: 14px;
  padding: 10px 14px;
}
.howto summary{
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  list-style: none;
}
.howto summary::-webkit-details-marker{ display:none; }
.howto summary::before{ content: '▸'; display:inline-block; margin-right:6px; color: var(--ink-muted); transition: transform .15s ease; }
.howto[open] summary::before{ transform: rotate(90deg); }
.howto ol{ margin: 10px 0 2px; padding-left: 20px; font-size: 13px; line-height: 1.55; color: var(--ink-soft); }
.howto li{ margin-bottom: 6px; }
.howto li:last-child{ margin-bottom: 0; }

.toolbar{
  display:flex;
  align-items:flex-end;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px;
  flex-wrap: wrap;
}

.field{ display:flex; flex-direction:column; gap:5px; min-width: 150px; }
.field--grow{ flex: 1 1 320px; }
.field label{ font-size: 11px; font-weight:600; color: var(--ink-soft); text-transform: uppercase; letter-spacing:.04em; }
.field input, .field select{
  border: 1px solid var(--border-strong);
  background: var(--surface-sunken);
  border-radius: var(--radius-s);
  padding: 9px 10px;
  height: 38px;
}
.field input:focus, .field select:focus{ background: var(--surface); }

.btn{
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  padding: 0 16px;
  height: 38px;
  font-weight: 600;
  cursor: pointer;
}
.btn--primary{ background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover{ background: var(--accent-dark); }
.btn--primary:disabled{ background: var(--ink-muted); cursor: progress; }
.btn--ghost{ background: transparent; border-color: var(--border-strong); color: var(--ink); }
.btn--ghost:hover{ background: var(--surface-sunken); }
.btn--submit{ min-width: 120px; }

/* ---------- banner ---------- */

.banner{
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-s);
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.banner--cache{ background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-dark); }
.banner--degraded{ background: var(--amber-bg); border-color: var(--amber-border); color: var(--amber-ink); }
.banner--error{ background: var(--red-bg); border-color: var(--red-border); color: var(--red-ink); }

/* ---------- results / compare table ---------- */

.results{ margin-top: 18px; }
.results__head{ display:flex; align-items:baseline; gap:10px; margin-bottom:8px; }
.results__count{ font-family: var(--font-mono); font-size:12px; color: var(--ink-muted); }
.btn--csv{ height:30px; padding:0 12px; font-size:12px; margin-left:auto; }
.btn--ai{ height:30px; padding:0 12px; font-size:12px; margin-left:8px; }

.ai-panel{
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  overflow: hidden;
}
.ai-panel__head{
  display:flex; align-items:center; justify-content:space-between;
  padding: 8px 12px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
}
.ai-panel__label{ font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.04em; color: var(--ink-soft); }
.ai-panel__head .icon-btn{ width:24px; height:24px; font-size:11px; }
.ai-panel__body{ padding: 12px 14px; font-size: 13px; line-height:1.55; }
.ai-panel__body p{ margin: 0 0 8px; }
.ai-panel__body p:last-child{ margin-bottom: 0; }
.ai-panel__note{
  display:flex; align-items:center; gap:6px;
  font-size: 12px; color: var(--ink-muted); margin-top: 8px;
}
.ai-panel__note--fallback{ color: var(--amber-ink); }
.ai-panel__note--down{ color: var(--red-ink); }
.ai-panel--down .ai-panel__body{ color: var(--red-ink); }
.ai-panel__spinner{
  width:12px; height:12px; border-radius:50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite; flex:none;
}
@keyframes spin{ to{ transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce){ .ai-panel__spinner{ animation-duration: 1.4s; } }

.table-wrap{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  /* no overflow:hidden here: it would make this the sticky-positioning
     container for the <th> below and break "position: sticky" math.
     Rounded corners are applied directly to the outer cells instead. */
}
.table-wrap table.compare thead th:first-child{ border-top-left-radius: var(--radius-m); }
.table-wrap table.compare thead th:last-child{ border-top-right-radius: var(--radius-m); }
.table-wrap table.compare tbody tr:last-child td:first-child{ border-bottom-left-radius: var(--radius-m); }
.table-wrap table.compare tbody tr:last-child td:last-child{ border-bottom-right-radius: var(--radius-m); }

table.compare{ width:100%; border-collapse: collapse; }
table.compare th{
  text-align:left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-muted);
  font-weight:600;
  padding: 10px 14px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 61px;
}
table.compare td{
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 13px;
}
table.compare th.num, table.compare td.num{ text-align:right; font-family: var(--font-mono); }
table.compare th.sortable{ cursor:pointer; user-select:none; }
table.compare th.sortable:hover{ color: var(--ink); }
table.compare th.sortable::after{ content:'↕'; margin-left:4px; opacity:.5; }
table.compare th.sortable[data-dir="desc"]::after{ content:'↓'; opacity:1; }
table.compare th.sortable[data-dir="asc"]::after{ content:'↑'; opacity:1; }
table.compare tbody tr:last-child td{ border-bottom: none; }
table.compare tbody tr:hover{ background: var(--surface-sunken); }

.score{ display:inline-flex; align-items:center; gap:6px; justify-content:flex-end; }
.score__bar{
  width: 34px; height: 5px; border-radius: 3px;
  background: var(--surface-sunken);
  overflow: hidden; flex:none;
}
.score__bar-fill{ height:100%; background: var(--accent); border-radius: 3px; }
.score--low .score__bar-fill{ background: var(--ink-muted); }
.score--mid .score__bar-fill{ background: var(--amber-ink); }

.row-open{
  background:none; border:none; text-align:left; cursor:pointer;
  display:flex; flex-direction:column; gap:2px; padding:0; width: 100%;
}
.cell-name__title{ font-weight:600; }
.cell-name__id{ font-family: var(--font-mono); font-size: 11px; color: var(--ink-muted); }

.empty-row td{ padding: 28px 14px; color: var(--ink-muted); text-align:center; }

.na{ color: var(--ink-muted); font-style: italic; }

.badge{
  display:inline-flex; align-items:center; gap:4px;
  font-size: 11px; font-weight:600;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--amber-border);
  background: var(--amber-bg);
  color: var(--amber-ink);
  margin-left: 6px;
  white-space: nowrap;
  font-family: var(--font-ui);
}

.badge--down{ border-color: var(--red-border); background: var(--red-bg); color: var(--red-ink); }

.price-value{ font-family: var(--font-mono); }

.skeleton-row td{ padding: 12px 14px; }
.skeleton-bar{
  height: 12px; border-radius: 3px;
  background: linear-gradient(90deg, var(--surface-sunken) 25%, #ddd7c4 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer{ 0%{ background-position: 100% 0; } 100%{ background-position: 0 0; } }
@media (prefers-reduced-motion: reduce){ .skeleton-bar{ animation: none; } }

.row-enter{ animation: rowIn .22s ease both; }
@keyframes rowIn{ from{ opacity:0; transform: translateY(3px);} to{ opacity:1; transform:none; } }
@media (prefers-reduced-motion: reduce){ .row-enter{ animation:none; } }

/* ---------- drawer ---------- */

.scrim{
  position: fixed; inset:0; background: rgba(28,30,22,0.35);
  z-index: 40; opacity:0; transition: opacity .18s ease;
}
.scrim.is-open{ opacity:1; }

.drawer{
  position: fixed; top:0; right:0; bottom:0;
  width: min(480px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-drawer);
  transform: translateX(100%);
  transition: transform .22s ease;
  z-index: 50;
  display:flex; flex-direction:column;
}
.drawer.is-open{ transform: translateX(0); }
@media (prefers-reduced-motion: reduce){ .drawer{ transition:none; } }

.drawer__head{
  display:flex; align-items:flex-start; justify-content:space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  gap: 12px;
}
.drawer__eyebrow{ margin:0 0 4px; font-size:11px; text-transform:uppercase; letter-spacing:.05em; color: var(--ink-muted); }
.drawer__body{ padding: 16px 20px 28px; overflow-y:auto; flex:1; }
.drawer__section{ margin-bottom: 22px; }
.drawer__section h3{ font-size: 13px; margin-bottom: 10px; }

.kv{ display:grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin:0; font-size:13px; }
.kv dt{ color: var(--ink-muted); }
.kv dd{ margin:0; }
.kv a{ color: var(--accent-dark); }

.drawer__why{
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius-m);
  padding: 12px 14px;
}
.drawer__why h3{ color: var(--accent-dark); }
.drawer__why p{ margin:0; font-size:13px; line-height:1.55; }

.tags{ display:flex; flex-wrap:wrap; gap:6px; }
.tag{
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-sunken); border: 1px solid var(--border);
  color: var(--ink-soft); white-space: nowrap;
}
.tag a{ color: inherit; text-decoration: underline; }

.score-factors{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:8px; }
.score-factors li{ display:flex; align-items:center; gap:10px; font-size:13px; }
.score-factors__label{ flex: 1 1 auto; color: var(--ink-soft); }
.score-factors__value{ font-family: var(--font-mono); font-size:12px; color: var(--ink-muted); flex:none; width: 52px; text-align:right; }
.score-factors__bar{ width: 80px; height:5px; border-radius:3px; background: var(--surface-sunken); overflow:hidden; flex:none; }
.score-factors__bar-fill{ height:100%; background: var(--accent); border-radius:3px; }
.score-factors li.is-zero .score-factors__bar-fill{ background: var(--border-strong); }

table.offers{ width:100%; border-collapse: collapse; font-size:13px; }
table.offers th{ text-align:left; font-size:11px; color: var(--ink-muted); text-transform:uppercase; padding: 6px 4px; border-bottom:1px solid var(--border); }
table.offers td{ padding: 7px 4px; border-bottom:1px solid var(--border); }
table.offers th.num, table.offers td.num{ text-align:right; font-family: var(--font-mono); }

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

.notes-list{ display:flex; flex-direction:column; gap:10px; margin-bottom:12px; max-height: 220px; overflow-y:auto; }
.note{
  border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: 8px 10px; background: var(--surface-sunken); font-size: 13px;
}
.note__meta{ font-size:11px; color: var(--ink-muted); margin-bottom:4px; font-family: var(--font-mono); }
.note__body{ white-space: pre-wrap; word-break: break-word; }

.note-form textarea{
  width:100%; min-height: 70px; resize: vertical;
  border: 1px solid var(--border-strong); border-radius: var(--radius-s);
  padding: 8px 10px; background: var(--surface-sunken);
}
.note-form__row{ display:flex; align-items:center; justify-content:space-between; margin-top:8px; }
.note-form__count{ font-family: var(--font-mono); font-size:11px; color: var(--ink-muted); }

/* ---------- responsive ---------- */

@media (max-width: 860px){
  .topbar{ flex-wrap: wrap; }
  .layout{ padding: 16px; }
  table.compare thead{ display:none; }
  table.compare, table.compare tbody, table.compare tr, table.compare td{ display:block; width:100%; }
  table.compare tr{ border-bottom: 1px solid var(--border); padding: 10px 14px; }
  table.compare td{ border-bottom:none; padding: 3px 0; }
  table.compare td.num{ text-align:left; }
  table.compare td::before{ content: attr(data-label); display:block; font-size:10px; text-transform:uppercase; color: var(--ink-muted); }
  .drawer{ width: 100vw; }
}
