:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1b1b1d;
  --ink-soft: #5c5c66;
  --ink-faint: #8a8a95;
  --line: #e2e0da;
  --accent: #35566f;
  /* Text drawn on top of --accent. It must flip with the accent: in dark mode the accent
     becomes light, and white-on-light-blue is unreadable. */
  --on-accent: #ffffff;

  --exact: #1f7a4d;
  --exact-bg: #e6f4ec;
  --caution: #9a6512;
  --caution-bg: #fbf0dc;
  --approx: #a1541b;
  --approx-bg: #fbeadb;
  --cross: #5d5f6b;
  --cross-bg: #ecedf0;
  --none: #97361f;
  --none-bg: #fbe6e1;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 25, .06), 0 4px 14px rgba(20, 20, 25, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --panel: #1e2024;
    --ink: #eceded;
    --ink-soft: #a8abb2;
    --ink-faint: #7d818a;
    --line: #2e3137;
    --accent: #8fb4cd;
    --on-accent: #14161a;

    --exact: #6cc795;
    --exact-bg: #17301f;
    --caution: #d9ae62;
    --caution-bg: #322715;
    --approx: #e0a072;
    --approx-bg: #352315;
    --cross: #a9adb8;
    --cross-bg: #262930;
    --none: #e59b87;
    --none-bg: #33201c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute only sets `display: none` at low priority, so any later `display` rule
   silently defeats it. Without this, #progress stays on screen because it is `display: flex`. */
[hidden] { display: none !important; }

/* Keeps the file input in the accessibility tree and focusable, unlike `hidden`, while the
   styled dropzone label provides the visible affordance. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 1180px; margin: 0 auto; padding: 0 20px 72px; }

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 20px 24px;
}
.topbar h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: -.015em;
}
.tagline {
  margin: 0;
  max-width: 62ch;
  color: var(--ink-soft);
}

/* --- upload ------------------------------------------------------------- */

#upload-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

#dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 38px 24px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
#dropzone:hover { border-color: var(--accent); }
/* The real input is visually hidden, so the label carries its focus ring. */
#dropzone:focus-within { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
#dropzone.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.dz-icon { font-size: 1.6rem; color: var(--ink-faint); line-height: 1; }
.dz-main { font-weight: 600; }
.dz-sub { color: var(--ink-faint); font-size: .85rem; max-width: 52ch; }

.file-name {
  margin: 14px 0 0;
  font-size: .9rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: opacity .15s, background .15s, border-color .15s;
}
#analyze-btn {
  margin-top: 16px;
  padding: 10px 20px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
#analyze-btn:disabled { opacity: .4; cursor: not-allowed; }

.ghost {
  padding: 7px 13px;
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
  font-size: .87rem;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.error {
  margin: 16px 0 0;
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--none-bg);
  color: var(--none);
  font-size: .9rem;
}

#progress { display: flex; align-items: center; gap: 11px; margin-top: 18px; color: var(--ink-soft); font-size: .92rem; }
.spinner {
  width: 17px; height: 17px; flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- summary ------------------------------------------------------------ */

#results { margin-top: 34px; }

.summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.summary h2 { margin: 0 0 4px; font-size: 1.15rem; }
.summary .sub { margin: 0 0 16px; color: var(--ink-faint); font-size: .87rem; }
.tally { display: flex; flex-wrap: wrap; gap: 10px; }
.tally-item {
  display: flex; align-items: baseline; gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
}
.tally-item b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
  margin: 24px 0 16px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 13px;
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
  font-size: .87rem;
}
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* --- cards -------------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.is-hidden { display: none; }

.card-head { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.code-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }

.swatch {
  width: 46px; height: 60px;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, .28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

.card-id .code { font-weight: 700; font-size: 1.02rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-id .chart, .card-id .qty { font-size: .82rem; color: var(--ink-faint); }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.exact { background: var(--exact-bg); color: var(--exact); }
.badge.exact_other_type,
.badge.exact_other_size { background: var(--caution-bg); color: var(--caution); }
.badge.approx_family { background: var(--approx-bg); color: var(--approx); }
.badge.approx_other_family { background: var(--approx-bg); color: var(--approx); }
.badge.approx_cross_brand { background: var(--cross-bg); color: var(--cross); }
.badge.none { background: var(--none-bg); color: var(--none); }

.note { margin: 0; font-size: .84rem; color: var(--ink-soft); }

.offers { display: flex; flex-direction: column; gap: 8px; }

.offer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  text-align: left;
  width: 100%;
}
.offer.selectable { cursor: pointer; }
.offer.selectable:hover { border-color: var(--accent); }
.offer.is-picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

.offer-thumbs { display: flex; align-items: center; gap: 3px; flex: none; }
.offer-thumbs img {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--bg);
  border: 1px solid var(--line);
}
/* The sampled photo colour sits flush against the pattern swatch so the colour call is
   checkable at a glance rather than taken on trust. */
.offer-thumbs .sampled {
  width: 15px; height: 52px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .22);
}

.offer-body { min-width: 0; }
.offer-title {
  font-size: .85rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.offer-meta {
  margin-top: 3px;
  font-size: .77rem;
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.offer-meta .oos { color: var(--none); font-weight: 600; }
/* Why this offer is on the list. Needed because the order deliberately favours Czech beads on
   near-ties, so the visible dE column is not strictly ascending. */
.offer-why { margin-top: 2px; font-size: .74rem; color: var(--ink-faint); font-style: italic; }
.offer-meta .quality { font-weight: 600; }
.offer-meta .q-good { color: var(--exact); }
.offer-meta .q-ok   { color: var(--caution); }
.offer-meta .q-poor { color: var(--none); }
.brand-tag {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--cross-bg);
  color: var(--cross);
  font-weight: 600;
  font-size: .72rem;
}

.offer-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.price { font-weight: 700; font-size: .93rem; font-variant-numeric: tabular-nums; }
.buy { font-size: .8rem; color: var(--accent); text-decoration: none; font-weight: 600; white-space: nowrap; }
.buy:hover { text-decoration: underline; }

.empty { font-size: .86rem; color: var(--ink-faint); font-style: italic; }

/* --- notes -------------------------------------------------------------- */

.notes {
  margin-top: 40px;
  padding: 22px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.notes h2 { margin: 0 0 12px; font-size: 1.02rem; }
.notes ul { margin: 0; padding-left: 20px; color: var(--ink-soft); font-size: .89rem; }
.notes li { margin-bottom: 9px; }
.notes li:last-child { margin-bottom: 0; }

@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
}
