:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7280;
  --line: #e4e7ec;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --good: #0a7a3f;
  --good-bg: #e6f4ec;
  --warn: #92600a;
  --warn-bg: #fdf2dc;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); }
.topbar nav a {
  margin-left: 18px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { color: var(--brand); }

.container { max-width: 960px; margin: 0 auto; padding: 32px 24px 64px; }
.container.wide { max-width: 1840px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px; }

h1 { font-size: 1.6rem; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 32px 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); background: var(--bad-bg); padding: 12px 14px; border-radius: 8px; }

/* Home */
.hero { text-align: center; padding-top: 24px; }
.hero .sub { color: var(--muted); font-size: 1.05rem; }
.bigbuttons {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
  max-width: 640px; margin: 32px auto;
}
.bigbtn {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  text-align: left; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; transition: transform .08s, box-shadow .12s, border-color .12s;
}
.bigbtn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.07); border-color: var(--brand); }
.bigbtn .ic { font-size: 1.8rem; }
.bigbtn .lab { font-weight: 700; font-size: 1.15rem; }
.bigbtn .desc { color: var(--muted); font-size: .9rem; }
.statrow { display: flex; gap: 28px; justify-content: center; margin-top: 24px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

/* Forms */
.searchform { display: flex; gap: 10px; margin: 18px 0 24px; flex-wrap: wrap; }
.searchform input[type=text] { flex: 1 1 320px; }
input, select, button, textarea { font: inherit; }
input[type=text], input[type=file], select {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
button, .btn {
  background: var(--brand); color: #fff; border: none; padding: 10px 18px;
  border-radius: 8px; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-block; text-align: center;
}
button:hover, .btn:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--brand); }

.uploadform { display: flex; flex-direction: column; gap: 16px; max-width: 520px; }
.uploadform label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.uploadform small { color: var(--muted); font-weight: 400; }
.uploadform button { align-self: flex-start; }

/* Search results */
.results { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.exact { border-color: var(--brand); }
.card-head { display: flex; justify-content: space-between; gap: 16px; }
.card-head h3 { margin: 0 0 2px; font-size: 1.1rem; }
.supplier { color: var(--muted); font-size: .85rem; }
.price { font-weight: 700; white-space: nowrap; font-size: 1.05rem; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.tag { background: #eef1f5; color: #384150; padding: 2px 8px; border-radius: 999px; font-size: .78rem; }
.tag.match { background: var(--good-bg); color: var(--good); }
.tag.score { background: #e8effd; color: var(--brand-dark); }
.desc { color: #374151; font-size: .92rem; margin: 6px 0; }
.src { font-size: .85rem; color: var(--brand); text-decoration: none; }
.hint { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; }
.hint ul { margin: 6px 0 0; }

/* Fixed (sticky) search controls at the top; results/PDF scroll beneath */
.search-header {
  position: sticky; top: 52px; z-index: 8; background: var(--bg);
  padding: 12px 0 12px; box-shadow: 0 6px 10px -8px rgba(0,0,0,.18);
}
.search-header .searchform { margin: 0 0 10px; }
.search-header .chips { margin: 0 0 8px; }
.resultcount { margin-top: 14px; }

/* Product selection + Email RFQ */
.action-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.action-hint { color: var(--muted); font-size: .8rem; }
.btn-email {
  background: #0d9488; color: #fff; border: none; padding: 6px 14px;
  border-radius: 999px; font-size: .84rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-email:hover:not(:disabled) { background: #0f766e; }
.btn-email:disabled { background: #c7c9d1; cursor: default; }
.rfq-panel { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; width: 100%; margin-top: 2px; }
.rfq-link {
  background: #e9f6f4; color: #0f766e; border: 1px solid #bfe4de; padding: 5px 12px;
  border-radius: 8px; font-size: .82rem; font-weight: 600; text-decoration: none;
}
.rfq-link:hover { background: #d9efec; }
.rfq-link.no-email { background: #fdf2dc; color: #92600a; border-color: #f0d9a8; }
.rfq-edit { font-size: .8rem; color: var(--brand); text-decoration: none; }
.cbcol { width: 34px; text-align: center; }
.cbcol input { cursor: pointer; }
.vendor-email { margin: 0 0 20px; }
.vendor-email label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.ve-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ve-row input { flex: 0 1 320px; }
.ve-ok { color: var(--good); font-size: .8rem; }
.ve-missing { color: var(--warn); font-size: .8rem; }

/* Related-keyword suggestion chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 20px; }
.chips-label { color: var(--muted); font-size: .85rem; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-empty { font-size: .82rem; }
.chip {
  display: inline-block; background: #eef3ff; color: var(--brand-dark);
  border: 1px solid #d6e2fb; padding: 4px 11px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.chip:hover { background: #dfeaff; border-color: var(--brand); }
/* Fine-tuned (live) chips — a distinct, legible colour vs the blue precomputed ones */
.chip.tuned { background: #e8f7ee; color: #0a7a3f; border-color: #bfe6cf; }
.chip.tuned:hover { background: #d7f0e2; border-color: var(--good); }
/* Distinct-colour on-demand button */
.btn-finetune {
  margin-left: auto; background: #7c3aed; color: #fff; border: none;
  padding: 6px 14px; border-radius: 999px; font-size: .82rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn-finetune:hover { background: #6d28d9; }
.btn-finetune:disabled { background: #c7c9d1; cursor: default; }

/* Split view: results on the left, PDF preview on the right */
.split { display: flex; gap: 20px; align-items: flex-start; }
/* Keep the results column at a steady width; let the PDF pane grow to fill
   the rest of the (now wider) page for a bigger document view. */
.split-left { flex: 0 1 820px; min-width: 0; }
.split-right { flex: 1 1 620px; min-width: 0; position: sticky; top: var(--sticktop, 76px); }
.pdf-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-bottom: 8px; font-size: .85rem; color: var(--muted);
}
.pdf-head a { color: var(--brand); text-decoration: none; font-weight: 600; white-space: nowrap; }
#pdfframe {
  width: 100%; height: calc(100vh - 120px); min-height: 420px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.pdf-ph {
  display: flex; align-items: center; justify-content: center; text-align: center;
  height: calc(100vh - 120px); min-height: 420px; padding: 24px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--muted);
}
a.refopen.active { font-weight: 700; text-decoration: underline; }
@media (max-width: 900px) {
  .split { flex-direction: column; }
  .split-right { display: none; }  /* on mobile, Ref opens in a new tab */
}

/* Tables */
.tablewrap { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.results-table td { font-size: .88rem; }
/* Tighter columns so every column (incl. Ref) fits without horizontal scroll */
.results-table th, .results-table td { padding: 6px 4px; }
.results-table th:first-child, .results-table td:first-child { padding-left: 6px; }
.results-table th:last-child, .results-table td:last-child { padding-right: 6px; }
.results-table .desccell { max-width: 150px; }
.results-table .pricecell { min-width: 84px; }
.results-table .refcell { text-align: right; }
.results-table .cbcol { width: 26px; }
.table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .9rem; vertical-align: top; }
.table th { background: #fafbfc; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table a { color: var(--brand); text-decoration: none; font-weight: 600; }
.desccell { max-width: 320px; color: #374151; }
.desc-clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4;
  line-clamp: 4; overflow: hidden;
}
.desc-clamp.open { -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }
.desc-more {
  background: none; border: none; color: var(--brand); padding: 0;
  font-size: .78rem; font-weight: 600; cursor: pointer; margin-top: 3px;
}
.desc-more:hover { background: none; text-decoration: underline; }
.pricecell { min-width: 150px; }
.pricecell .pk { color: var(--muted); font-size: .8rem; margin-bottom: 2px; }
.pricecell .pr-base { font-weight: 700; white-space: nowrap; }
.pricecell .pr-tier { font-size: .82rem; color: #374151; white-space: nowrap; }
.pricecell .pr-label { color: var(--muted); }
.rowact { display: flex; gap: 12px; align-items: center; }
.rowact form { margin: 0; }
.link { background: none; color: var(--brand); padding: 0; font-weight: 600; }
.link:hover { background: none; text-decoration: underline; }
.link.danger { color: var(--bad); }

/* Badges */
.badge { padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; text-transform: capitalize; }
.badge.ready { background: var(--good-bg); color: var(--good); }
.badge.processing, .badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.failed { background: var(--bad-bg); color: var(--bad); }

/* Catalogue detail */
.back { color: var(--muted); text-decoration: none; font-size: .9rem; }
.cat-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 8px 0 12px; flex-wrap: wrap; }
.cat-actions { display: flex; gap: 10px; align-items: center; }
.cat-actions form { margin: 0; }
.metaline { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; margin-bottom: 20px; align-items: center; }
.processing { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .bigbuttons { grid-template-columns: 1fr; }
  .cat-head { flex-direction: column; align-items: flex-start; }
}
