/* QR Studio — sticky preview + frame-template picker.
   Load AFTER style.css. Uses your theme variables when present, with fallbacks. */

:root { --sticky-top: 84px; }

/* ───────── 1. Preview always visible ───────── */
/* align-self:start is essential: a stretched grid item can never "stick". */
.app-grid { align-items: start; }

.preview-col {
  position: sticky;
  top: var(--sticky-top);
  align-self: start;
  z-index: 20;                 /* no max-height / overflow: the image below shrinks to fit, so no scrollbar */
}
.preview-col .qr-stage img,
.preview-col .frame-out {
  max-height: max(180px, min(560px, calc(100vh - var(--sticky-top) - 290px)));
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.frame-out { display: block; margin: 0 auto; }
.frame-out[hidden] { display: none; }
.qr-stage.has-frame #qrPreview { display: none; }

/* Single-column (phones / small tablets): keep a compact preview pinned to the top */
@media (max-width: 960px) {
  :root { --sticky-top: 0px; }
  .preview-col {
    order: -1;               /* first in the single column, so it can pin to the top while the controls scroll under it */
    max-height: none;
    overflow: visible;
    box-shadow: 0 10px 24px -14px rgba(15, 23, 42, .45);
  }
  .preview-col .preview-card { padding-block: 10px; }
  .preview-col .qr-stage img,
  .preview-col .frame-out { max-height: 30vh; }
  .preview-col .tip,
  .preview-col .actions + .actions { display: none; }
  .preview-col .actions { gap: 8px; }
}

/* ───────── 2. Frame template picker ───────── */
.tpl-hint { margin: -4px 0 12px; color: var(--muted, #6b7280); font-size: .9rem; }
.tpl-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.tpl-chip {
  font: inherit; font-size: .82rem; line-height: 1;
  padding: 7px 11px; border-radius: 999px; cursor: pointer;
  color: var(--text, #111827); background: transparent;
  border: 1px solid var(--border, #d1d5db);
}
.tpl-chip:hover { border-color: var(--accent, #4f46e5); }
.tpl-chip[aria-pressed="true"] { background: var(--accent, #4f46e5); border-color: var(--accent, #4f46e5); color: #fff; }
.tpl-chip.small { font-size: .78rem; padding: 6px 10px; }

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  padding: 4px 2px 6px;
  margin-bottom: 12px;
}
.tpl-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 6px 6px; cursor: pointer; font: inherit;
  border-radius: 12px; border: 2px solid var(--border, #e5e7eb);
  background: var(--card, #fff); color: var(--text, #111827);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.tpl-item img { width: 100%; max-width: 84px; height: auto; display: block; }
.tpl-item span { font-size: .72rem; line-height: 1.2; text-align: center; color: var(--muted, #6b7280); }
.tpl-item:hover { transform: translateY(-2px); border-color: var(--accent, #4f46e5); }
.tpl-item[aria-pressed="true"] { border-color: var(--accent, #4f46e5); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #4f46e5) 25%, transparent); }
.tpl-item.pop::after {
  content: "★"; position: absolute; top: 4px; inset-inline-end: 6px;
  font-size: .8rem; color: #f59e0b;
}

#tplOptions { border-top: 1px solid var(--border, #e5e7eb); padding-top: 12px; }
#tplOptions[hidden] { display: none; }
.tpl-cta { margin-top: 8px; }

/* ───────── 3. Bulk CSV ───────── */
.dropzone.over { border-color: var(--accent, #4f46e5); }
.bulk-list { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.bulk-list:empty { display: none; }
.bulk-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--border, #e5e7eb); border-radius: 10px; }
.bulk-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-meta { color: var(--muted, #6b7280); font-size: .82rem; }
.bulk-x { border: 0; background: transparent; cursor: pointer; color: var(--muted, #6b7280); font-size: 1rem; line-height: 1; }
.bulk-x:hover { color: #dc2626; }
.bulk-prog { width: 100%; height: 10px; margin-top: 10px; accent-color: var(--accent, #4f46e5); }
.bulk-prog[hidden], #bulkCancel[hidden] { display: none; }

.bulk-cols { margin: 0 0 12px; padding: 8px 12px 6px; border: 1px solid var(--border, #e5e7eb); border-radius: 12px; min-inline-size: 0; }
.bulk-cols legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }
.bulk-cols-tools { font-size: .82rem; margin-bottom: 4px; color: var(--muted, #6b7280); }
.bulk-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border, #eef0f3); }
.bulk-col:first-child { border-top: 0; }
.bulk-col-lab { display: flex; align-items: center; gap: 8px; cursor: pointer; min-width: 0; }
.bulk-col-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bulk-sample { color: var(--muted, #6b7280); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-map { font: inherit; font-size: .82rem; max-width: 120px; }
.bulk-map[hidden], .check[hidden] { display: none; }

/* ===================================================== content tabs — flat, neutral, one brand colour */
.card .tabs > button:not([hidden]) {
  background: color-mix(in srgb, var(--accent, #4f46e5) 6%, transparent);
  border: 1px solid transparent; color: inherit; font-weight: 500;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.card .tabs > button:not([hidden]):hover { background: color-mix(in srgb, var(--accent, #4f46e5) 14%, transparent); }
.card .tabs > button[aria-selected="true"]:not([hidden]),
.card .tabs > button.is-on:not([hidden]) {
  background: var(--accent, #4f46e5); border-color: var(--accent, #4f46e5); color: #fff;
}
.card .tabs > button[hidden] { display: none; }
/* "Bulk Code" is a different kind of action, so it is outlined and kept apart from the single-QR tabs */
.card .tabs > #bulkTab:not(.is-on) {
  background: transparent; border: 1px dashed color-mix(in srgb, var(--accent, #4f46e5) 55%, transparent);
  color: var(--accent, #4f46e5); margin-inline-start: auto;
}
.card .tabs > #bulkTab:not(.is-on):hover { background: color-mix(in srgb, var(--accent, #4f46e5) 10%, transparent); }

/* Phone / Text switch */
.seg { display: inline-flex; margin: 0 0 12px; border: 1px solid var(--border, #e5e7eb); border-radius: 999px; overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; padding: 6px 14px; border: 0; cursor: pointer; background: transparent; color: inherit; }
.seg button[aria-pressed="true"] { background: var(--accent, #4f46e5); color: #fff; }

/* Bulk Code mode: the bulk card replaces the single-content panels */
#bulkCard { display: none; }
.bulk-mode .panel { display: none !important; }
.bulk-mode #bulkCard { display: block; margin-top: 14px; box-shadow: none; border: 0; padding: 0; background: transparent; }
.bulk-mode .tabs > button:not(#bulkTab)[aria-selected="true"],
.bulk-mode .tabs > button:not(#bulkTab).is-on:not([aria-selected="true"]) {
  background: color-mix(in srgb, var(--accent, #4f46e5) 6%, transparent); border-color: transparent; color: inherit;
}
