/* ===========================================================
   Swap Sheet — design system
   Structure stays black/white/minimal; accent colors are drawn
   from the provided palette and mapped to specific functional
   roles rather than used indiscriminately.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Archivo+Black&family=Noto+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #101112;
  --ink-soft: #2b2d30;
  --paper: #ffffff;
  --paper-dim: #f4f3ef;
  --line: #d8d5cc;

  /* Primary brand accent — variable name kept as --gold for minimal
     churn, but now holds the palette's violet rather than literal gold */
  --gold: #5b0fdc;
  --gold-light: #e7dcfb;

  /* Functional accents, drawn from the same palette */
  --blue: #3355f4;    /* links */
  --red: #c0392b;     /* danger / remove */
  --green: #4caf63;   /* success / saved confirmation */
  --orange: #e8571f;  /* parallel / special-treatment highlight */

  --radius: 6px;
  --tap-min: 44px; /* minimum comfortable touch target */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Noto Sans', Arial, sans-serif;
  color: var(--ink);
  background: var(--paper-dim);
  margin: 0;
  padding: 0 16px 60px;
  line-height: 1.45;
}

.page-shell {
  max-width: 980px;
  margin: 0 auto;
}

/* ---------- Header / brand mark ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 3px solid var(--ink);
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark .mark {
  flex-shrink: 0;
  display: block;
}
.brand-mark .word {
  font-family: 'Archivo Black', sans-serif;
  font-size: 17px;
  letter-spacing: 0.023em;
  text-transform: uppercase;
}
.header-links {
  margin-left: auto;
  display: flex;
  gap: 16px;
  font-size: 14px;
}
.header-links a { color: var(--ink); }

h1, h2, h3 {
  font-family: 'Archivo Black', sans-serif;
  font-weight: 400; /* Archivo Black is already heavy */
  letter-spacing: 0.01em;
  line-height: 1.15;
}
h1 { font-size: 26px; margin: 6px 0 14px; }
h2 { font-size: 18px; margin: 22px 0 10px; }

a { color: var(--blue); }
.muted { color: #6b6a63; font-size: 13px; }
.error { color: var(--red); font-weight: 600; }

/* ---------- Layout helpers ---------- */
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.stack { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Form controls (touch-friendly) ---------- */
input, select, button, textarea {
  font-family: 'Noto Sans', Arial, sans-serif;
  font-size: 15px;
  padding: 9px 10px;
  min-height: var(--tap-min);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-light);
}

button, a.btn {
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--ink);
  color: var(--paper);
  border: none;
  cursor: pointer;
  padding: 10px 18px;
  transition: opacity 0.15s ease;
}
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}
button:hover, a.btn:hover { opacity: 0.85; }
button:active, a.btn:active { opacity: 0.7; }

button.gold, a.btn.gold { background: var(--gold); color: var(--paper); }
button.outline, a.btn.outline { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
button.danger, a.btn.danger { background: var(--red); }
button.small, a.btn.small { font-size: 11px; padding: 6px 10px; min-height: 34px; }

/* Looks exactly like a text link, but stays a real <button> since it performs
   an in-page action rather than navigating — used for things like "Delete set"
   sitting inline next to actual <a> links. */
.link-btn {
  background: none;
  border: none;
  padding: 2px 0;
  margin: 0;
  min-height: auto;
  font-family: 'Noto Sans', Arial, sans-serif;
  font-size: 14px;
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
  color: var(--blue);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { opacity: 0.75; }
.link-btn.danger-link { color: var(--red); }

fieldset {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 18px;
}
.fieldset-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: -2px 0 10px;
}

/* ---------- Fill Your Album — visual sticker-slot checklist ---------- */
.spread {
  display: flex;
  gap: 0;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  margin-top: 14px;
}
.page-half {
  flex: 1;
  padding: 18px;
  min-width: 0;
}
.spine {
  width: 14px;
  background: linear-gradient(90deg, rgba(0,0,0,0.06), rgba(0,0,0,0.14), rgba(0,0,0,0.06));
  flex-shrink: 0;
}
.album-header {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 3px solid var(--ink); padding-bottom: 10px; margin-bottom: 14px;
}
.album-header h2 { font-family: 'Archivo Black', sans-serif; font-size: 16px; text-transform: uppercase; margin: 0; letter-spacing: 0.02em; }
.album-header .code { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: #6b6a63; }

.slot-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
}
.slot-grid.auto-rows { grid-template-rows: none; grid-auto-rows: 1fr; }
.slot {
  position: relative;
  border-radius: 8px;
  border: 2.5px dashed var(--line);
  background: var(--paper-dim);
  aspect-ratio: 1 / 1.05;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 4px;
  cursor: pointer;
  transition: all .12s ease;
}
.slot .num {
  position: absolute; top: 5px; left: 6px;
  font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 10px; color: #8a8779;
}
.slot .name { font-size: 10.5px; line-height: 1.15; color: #6b6a63; margin-top: 4px; font-weight: 500; }

.slot.checked {
  border-style: solid;
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--gold), #7a2ff0);
}
.slot.checked .num { color: rgba(255,255,255,0.85); }
.slot.checked .name { color: #fff; font-weight: 700; }

.slot.locked {
  border-color: var(--green);
  background: linear-gradient(135deg, var(--green), #2e8b4f);
  cursor: default;
}
.slot.locked .dup-badge {
  position: absolute; bottom: 4px; right: 6px;
  font-family: 'Archivo Black', sans-serif; font-size: 7.5px; text-transform: uppercase;
  background: rgba(0,0,0,0.25); color: #fff; padding: 1px 4px; border-radius: 6px;
}

.slot.empty-slot {
  border-style: solid;
  border-color: transparent;
  background: repeating-linear-gradient(45deg, #e9e6dd, #e9e6dd 4px, #f4f3ef 4px, #f4f3ef 8px);
  cursor: default;
}

.slot.wide { grid-column: span 2; aspect-ratio: auto; }

.album-legend { display: flex; gap: 18px; margin-top: 14px; font-size: 12px; color: #6b6a63; align-items: center; flex-wrap: wrap; }
.album-legend .swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; vertical-align: middle; margin-right: 5px; }

/* ---------- EXPERIMENTAL: duplicate-entry-manager grid slots ---------- */
/* Reuses the same .slot / .slot-grid / .spread album layout as the plain
   checklist, but each slot is taller to fit a tap-zone (toggles "have it",
   same as the plain checklist) plus three tiny extras counters below it. */
.slot.dupe-slot { aspect-ratio: auto; padding: 0; overflow: visible; cursor: default; min-width: 0; }
.slot-tap-zone {
  width: 100%; box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6px 4px; cursor: pointer;
  min-width: 0; min-height: 62px;
}
.slot.dupe-slot .num { position: static; margin-bottom: 2px; }
.slot.dupe-slot .name { overflow-wrap: break-word; word-break: break-word; max-width: 100%; }

/* A softer "have it" fill than the plain checklist's bolder violet -- scoped
   to this page only via .dupe-slot, so checklist.html is unaffected. */
.slot.dupe-slot.checked {
  background: linear-gradient(135deg, #ded0f7, #cdb9f2);
  border-color: var(--gold);
}
.slot.dupe-slot.checked .num { color: #6d5a94; }
.slot.dupe-slot.checked .name { color: var(--ink); font-weight: 700; }

.extras-mini { width: 100%; display: flex; flex-direction: column; }
.mini-row {
  display: flex; align-items: center; gap: 2px;
  padding: 3px 5px;
  font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 600;
  box-sizing: border-box;
}
.mini-row.base { background: var(--paper); }
.mini-row.blue { background: var(--blue); color: #fff; }
.mini-row.red { background: var(--red); color: #fff; }
.mini-row .mini-label { flex: 1; text-transform: uppercase; }
.mini-row .mini-val { min-width: 12px; text-align: center; }
.mini-row button {
  width: 18px; height: 18px; min-width: 18px; min-height: 0; max-width: 18px;
  padding: 0; line-height: 1; box-sizing: border-box;
  border-radius: 3px; font-size: 11px; font-weight: 700;
  border: 1px solid currentColor; background: transparent; color: inherit;
  opacity: 0.85;
}
.mini-row button:active { opacity: 1; transform: scale(0.92); }

.list-tabs {
  display: flex;
  gap: 6px;
  margin: 6px 0 14px;
}
.list-tabs .ltab {
  font-family: 'Archivo Black', sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 9px 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  border: 1.5px solid var(--line);
  border-bottom: none;
  background: var(--paper-dim);
  color: #6b6a63;
}
.list-tabs .ltab.active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
}
.list-tabs .ltab .count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  margin-left: 5px;
  opacity: 0.7;
}

.toolbar {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.toolbar label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b6a63;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Group headers (country / treatment sections) ---------- */
.group-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 13px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  padding: 7px 12px;
  border-radius: var(--radius) var(--radius) 0 0;
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.group-title::before {
  content: "";
  width: 9px; height: 9px;
  background: var(--gold);
  display: inline-block;
  border-bottom-right-radius: 9px;
}

/* ---------- Sticker table ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--line);
  border-top: none;
  margin-bottom: 4px;
}
th, td {
  padding: 8px 10px;
  text-align: left;
  font-size: 13.5px;
  border-bottom: 1px solid var(--paper-dim);
}
th {
  background: var(--paper-dim);
  font-family: 'Archivo Black', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b6a63;
}
td.mono, .mono { font-family: 'IBM Plex Mono', monospace; }
tr:last-child td { border-bottom: none; }

.qty-input { width: 60px; }

/* Treatment badges */
.treatment-base { color: #6b6a63; font-size: 12px; text-transform: uppercase; }
.treatment-blue { color: var(--blue); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.treatment-green { color: var(--green); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.treatment-purple { color: var(--gold); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.treatment-red { color: var(--red); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.treatment-black { color: var(--ink); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.treatment-parallel { color: var(--orange); font-weight: 700; font-size: 12px; text-transform: uppercase; } /* fallback for unrecognized values */

.set-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}
.set-list a {
  display: inline;
}
.set-card {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 0;
}
@media (max-width: 640px) {
  .set-list { grid-template-columns: 1fr; }
}

.share-subheading {
  font-family: 'Archivo Black', sans-serif;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b6a63;
  margin-top: 10px;
}
.ext-icon {
  font-size: 0.8em;
  vertical-align: middle;
  display: inline-block;
}

.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.qr-overlay-inner {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 28px 24px 22px;
  max-width: 320px;
  width: 100%;
  position: relative;
  text-align: center;
}
.qr-overlay-inner img {
  width: 100%;
  max-width: 260px;
  height: auto;
}
.qr-overlay-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--ink);
  font-size: 20px;
  padding: 8px 12px;
  min-height: auto;
  cursor: pointer;
}

#qrImg {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--paper);
}

/* ===========================================================
   Responsive behavior
   =========================================================== */

/* Tablet and down: tighten spacing, allow toolbar to wrap */
@media (max-width: 820px) {
  body { padding: 0 12px 50px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .row { margin-bottom: 0; }
}

/* Phone: stack forms, and turn tables into label/value cards */
@media (max-width: 640px) {
  h1 { font-size: 21px; }
  .row { flex-direction: column; align-items: stretch; }
  .row input, .row select, .row button { width: 100%; }
  fieldset .row > * { width: 100%; }

  /* Responsive table -> stacked cards pattern */
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  thead { display: none; }
  table {
    border: none;
    background: transparent;
  }
  tr {
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 0;
    overflow: hidden;
  }
  td {
    border-bottom: 1px solid var(--paper-dim);
    padding-left: 42%;
    position: relative;
    min-height: 38px;
    display: flex;
    align-items: center;
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    position: absolute;
    left: 10px;
    width: 38%;
    font-family: 'Archivo Black', sans-serif;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6b6a63;
  }
  td input, td select { width: 100%; }
  .qty-input { width: 100%; }

  .group-title { border-radius: var(--radius); }
}

@media print {
  @page { size: letter; margin: 0.4in; }

  .no-print { display: none !important; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body { background: #fff; padding: 0; font-size: 9.5px; color: #000; }
  .page-shell { max-width: none; }

  .site-header { border-bottom: 1.5px solid #000; padding: 4px 0; margin-bottom: 6px; }
  .brand-mark .mark { width: 14px; height: 14px; }
  .brand-mark .word { font-size: 13px; }

  h1 { font-size: 15px; margin: 4px 0 2px; }
  #updatedNote { font-size: 8.5px; margin: 0 0 6px; }

  /* Cancel the mobile stacked-card table pattern regardless of print viewport width */
  table, thead, tbody, th, td, tr { display: revert !important; width: revert !important; }
  thead { display: table-header-group !important; }
  td::before { content: none !important; }

  /* Flow the country/treatment groups into newspaper-style columns to fit
     hundreds of stickers on as few printed pages as possible. */
  #stickerTable { column-width: 235px; column-gap: 16px; }
  .group-title {
    break-inside: avoid;
    font-size: 9.5px;
    padding: 2px 2px 2px 7px;
    margin-top: 6px;
    background: transparent !important;
    color: #000 !important;
    border-left: 4px solid var(--gold);
    border-bottom: 1px solid #000;
  }
  .group-title::before { display: none; }

  table {
    break-inside: avoid;
    margin-bottom: 2px;
    border: 1px solid #999;
  }
  th, td {
    padding: 1px 4px;
    font-size: 8.5px;
    border-bottom: 1px solid #ddd;
    line-height: 1.3;
  }
  th { background: #eee !important; font-size: 7.5px; }

  .toolbar, #countSummary { display: none !important; }
}
