/* Files & Models: the models as a filmstrip gallery (project-models.js),
   in the editor and on the project page. Same look as the `::: gallery
   filmstrip` block (markdown-editor/gallery.css), using the page tokens
   --border, --surface, --muted, --text and --accent. */
.kr-models {
  --kr-models-radius: 10px;
  margin: 0 0 1rem;
}

.kr-models-stage {
  position: relative;
  margin-bottom: 0.5rem;
}

.kr-models-hero {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 360px;
  padding: 0;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--kr-models-radius);
  background: radial-gradient(circle at 50% 45%, #fff, var(--surface, #f3f4f6) 75%);
  overflow: hidden;
}
.kr-models-hero.is-clickable { cursor: zoom-in; }

/* The big preview is the model itself, drawn in 3D: drag to turn it
   (Kev, 2026-11-02). Its picture shows until the model has loaded. A
   vertical swipe on a phone still scrolls the page. */
.kr-models-hero.is-live { cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.kr-models-hero.is-live.is-turning { cursor: grabbing; }
.kr-models-hero .model-viewer__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.kr-models-hero.is-3d .model-viewer__canvas { opacity: 1; }
.kr-models-hero.is-3d .kr-models-hero-img,
.kr-models-hero.is-3d .kr-model-badge { visibility: hidden; }
.kr-models-hero.is-loading-3d .kr-model-badge { animation: kr-models-pulse 1s ease-in-out infinite alternate; }
@keyframes kr-models-pulse { from { opacity: 1; } to { opacity: 0.3; } }

/* "Drag to turn" under the model, faint until hovered. */
.kr-models-hint {
  position: absolute;
  left: 50%;
  bottom: 0.6rem;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
  pointer-events: none;
  opacity: 0.7;
  white-space: nowrap;
}
.kr-models-hint i { margin-right: 0.3rem; }
.kr-models-stage:hover .kr-models-hint { opacity: 1; }

.kr-models-hero-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 1rem;
}

/* The Open 3D viewer pill sits over the bottom of the big picture. */
.kr-models-open {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.18);
}
.kr-models-open:hover { filter: brightness(1.08); }

/* With the model live in the preview, full screen is a small icon button
   in the bottom right corner: no outline (Kev, 2026-11-02), and the glyph
   centred the claude.md way (block + line-height = height, not flex). */
.kr-models-open.is-icon {
  left: auto;
  right: 0.6rem;
  bottom: 0.6rem;
  transform: none;
  display: block;
  width: 32px;
  height: 32px;
  padding: 0;
  text-align: center;
  line-height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #4b5563);
  box-shadow: none;
  font-size: 1rem;
}
.kr-models-open.is-icon > i {
  display: inline-block;
  vertical-align: top;
  line-height: inherit;
  width: auto !important; /* beat the site-wide i { width: 16px !important } */
  margin: 0;
}
.kr-models-open.is-icon:hover { color: var(--accent, #2563eb); background: rgb(0 0 0 / 0.05); filter: none; }
.kr-models-open.is-icon:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }

/* A cube in the corner: this picture is rendered from the model. Just
   the icon, no box (Kev, 2026-10-31). */
.kr-model-badge {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  color: var(--accent, #2563eb);
  font-size: 0.95rem;
  line-height: 1;
  pointer-events: none;
}
.kr-model-badge i { display: block; margin: 0; line-height: 1; }

.kr-model-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--muted, #6b7280);
  opacity: 0.6;
}
.kr-models-hero .kr-model-placeholder { font-size: 4rem; }

/* The strip: every model, the shown one outlined. */
.kr-models-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 7.5rem;
  gap: 0.5rem;
  overflow-x: auto;
  /* Room for the selected outline (2px + 1px offset): a scrolling strip
     clips anything outside its padding box. */
  padding: 4px 4px 0.4rem;
  scroll-padding-inline: 4px;
  scroll-snap-type: x proximity;
}
.kr-models[data-count="1"] .kr-models-strip { display: none; }

.kr-models-thumb {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted, #6b7280);
  font-size: 0.75rem;
  text-align: center;
  opacity: 0.75;
  scroll-snap-align: start;
}
.kr-models-thumb:hover,
.kr-models-thumb.is-active { opacity: 1; color: var(--text, inherit); }

/* No box round the pictures (Kev, 2026-11-02): the model on the page,
   the shown one marked by a bar under its name. */
.kr-models-thumb-pic {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}
.kr-models-thumb-name { padding-bottom: 0.15rem; border-bottom: 2px solid transparent; }
.kr-models-thumb.is-active .kr-models-thumb-name {
  border-bottom-color: var(--accent, #2563eb);
  font-weight: 600;
}
.kr-models-thumb:focus-visible { outline: none; }
.kr-models-thumb:focus-visible .kr-models-thumb-pic { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.kr-models-thumb-pic .kr-model-placeholder { font-size: 1.6rem; }
.kr-models-thumb-pic .kr-model-badge { top: 0.3rem; right: 0.35rem; font-size: 0.75rem; }

.kr-models-thumb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.kr-models-thumb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The shown model's name, description and print settings. */
.kr-models-details {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--kr-models-radius);
  font-size: 0.9rem;
}
.kr-models-details-main { flex: 1; min-width: 0; }
.kr-models-details-name { font-weight: 600; word-break: break-word; }
.kr-models-details-meta { color: var(--muted, #6b7280); font-size: 0.8rem; }
.kr-models-details-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* The Download files button under the files. */
.kr-download-files {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  margin-top: 0.75rem;
}


/* A coloured model's picture is redrawn in its colour; hidden until then
   so the green render doesn't flash. */
img.is-tinting { visibility: hidden; }

/* Editor: where the files show on the page (the Files & Models heading). */
.kr-files-placement {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin: -0.25rem 0 0.75rem;
  color: var(--muted, #6b7280);
  font-size: 0.85rem;
}
.kr-files-placement[hidden] { display: none; }
.kr-files-placement .fa-check { color: var(--accent, #2563eb); }
.kr-files-placement.is-missing { color: var(--text, inherit); }
.kr-files-placement.is-missing .fa-info-circle { color: #b45309; }
.drop-progress__ask {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border, #e5e7eb);
  font-size: 0.85rem;
}

/* ---- Print details: qty, colour, filament ---------------------------- */
.kr-swatch {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border-radius: 50%;
  border: 1px solid rgb(0 0 0 / 0.25);
  vertical-align: -0.1em;
  flex-shrink: 0;
}
.kr-swatch.is-unknown { border-style: dashed; background: transparent; }

.kr-print-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.4rem;
  margin: 0.35rem 0 0.15rem;
}
.kr-print-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.05rem 0.55rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.kr-print-chip .fas { color: var(--muted, #6b7280); font-size: 0.75em; }

/* ---- Filmstrip / Table switch ------------------------------------------ */
.kr-models-views {
  display: inline-flex;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.kr-models-view {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.65rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted, #6b7280);
  font-size: 0.8rem;
  line-height: 1.5;
}
.kr-models-view:hover { color: var(--text, inherit); }
.kr-models-view.is-active { background: var(--accent, #2563eb); color: #fff; }
.kr-models-view:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.kr-models-viewbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin: -0.25rem 0 0.5rem;
}
.kr-models-viewbar small { color: var(--muted, #6b7280); }

/* ---- Table view ---------------------------------------------------------- */
.kr-models-table-wrap { position: relative; overflow-x: auto; margin-bottom: 1rem; }
.kr-models-table { font-size: 0.9rem; }
.kr-models-table th { font-size: 0.75rem; font-weight: 600; color: var(--muted, #6b7280); white-space: nowrap; }
.kr-models-table td { vertical-align: middle; }
.kr-models-table-pic { width: 64px; padding-right: 0 !important; }
.kr-models-table-thumb {
  position: relative;
  display: block;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  background: none;
  overflow: hidden;
  cursor: zoom-in;
}
.kr-models-table-thumb:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 2px; border-radius: 6px; }
.kr-models-table-thumb[disabled] { cursor: default; }
.kr-models-table-thumb .kr-model-badge { display: none; }
.kr-models-table-img { display: block; width: 100%; height: 100%; object-fit: contain; }
.kr-models-table-thumb .kr-model-placeholder { font-size: 1.3rem; }
.kr-models-table .kr-col-qty { width: 4.5rem; text-align: center; white-space: nowrap; }
.kr-models-table .kr-col-colour { min-width: 7rem; white-space: nowrap; }
.kr-models-table .kr-col-filament { min-width: 6rem; }
.kr-models-table .kr-col-size { white-space: nowrap; text-align: right; color: var(--muted, #6b7280); font-size: 0.8rem; }
.kr-models-table .kr-unset { color: var(--muted, #6b7280); opacity: 0.6; }

/* Editor: the print fields as quiet inputs that look like text until
   hovered or focused, in the table and under the filmstrip. */
.kr-print-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted, #6b7280);
}
.kr-print-inputs label { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0; }
.kr-print-input {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text, inherit);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.1rem 0.35rem;
  min-width: 0;
}
.kr-print-input::placeholder { color: var(--muted, #6b7280); opacity: 0.7; font-style: italic; }
.kr-print-input:hover { border-color: var(--border, #e5e7eb); }
.kr-print-input:focus { border-color: var(--accent, #2563eb); outline: none; background: var(--bs-body-bg, #fff); }
.kr-print-input[data-field="print_qty"] { width: 3.6rem; text-align: center; }
.kr-print-input[data-field="print_colour"] { width: 6.5rem; }
.kr-print-input[data-field="filament"] { width: 6.5rem; }
.kr-colour-field { display: inline-flex; align-items: center; gap: 0.15rem; }
/* The colour picker drawn as the swatch itself. */
.kr-colour-pick {
  position: relative;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid rgb(0 0 0 / 0.25);
  overflow: hidden;
  cursor: pointer;
}
.kr-colour-pick.is-empty { border-style: dashed; background: transparent !important; }
.kr-colour-pick input {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  opacity: 0;
  cursor: pointer;
}

@media (max-width: 576px) {
  .kr-models-view span { display: none; }
  .kr-models-strip { grid-auto-columns: 5.5rem; }
  .kr-models-hero { aspect-ratio: 4 / 3; }
}

/* Editor: the panel in the text, under the author's Files & Models (or
   3D printed parts) heading. That heading names it, so its own title steps
   back and its buttons sit on the right. */
#editor-files-section.is-in-text { margin: 0; padding: 0; border: 0; }
#editor-files-section.is-in-text .kr-section-head { justify-content: flex-end; border: 0; padding-top: 0; margin-bottom: 0.25rem; }
#editor-files-section.is-in-text .kr-section-title { display: none; }
#editor-files-section.is-in-text .kr-section-hint { margin-bottom: 0.5rem; }
/* The editor styles inputs in its text; these stay quiet until used. */
#editor-files-section.is-in-text .kr-print-input { border-color: transparent; background: transparent; box-shadow: none; }
#editor-files-section.is-in-text .kr-print-input:hover { border-color: var(--border, #e5e7eb); }
#editor-files-section.is-in-text .kr-print-input:focus { border-color: var(--accent, #2563eb); background: var(--bs-body-bg, #fff); }

/* Sortable table headers: the label is a button, the arrow shows the order. */
.kr-models-table th.kr-sortable { padding-top: 0; padding-bottom: 0; vertical-align: middle; }
.kr-models-table .kr-sort {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.5rem 0; border: 0; background: none; box-shadow: none;
  font: inherit; color: inherit; cursor: pointer; white-space: nowrap;
}
.kr-models-table .kr-sort:hover,
.kr-models-table .kr-sort.is-active { color: var(--text, #111827); }
.kr-models-table .kr-sort:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 2px; border-radius: 4px; }
.kr-models-table .kr-sort i { width: auto !important; font-size: 0.7rem; opacity: 0.45; }
.kr-models-table .kr-sort.is-active i { opacity: 1; }
.kr-models-table th.kr-col-size .kr-sort { flex-direction: row-reverse; }
.kr-models-table th.kr-col-size { font-size: 0.75rem; }

/* The project's storage at the top of Files & Models: used and left of its limit. */
.kr-files-quota { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--muted); }
.kr-files-quota-text { display: flex; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.3rem; }
.kr-files-quota-text strong { color: var(--text); font-weight: 600; }
.kr-files-quota-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.kr-files-quota-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s; }
.kr-files-quota.is-near .kr-files-quota-bar > span { background: #d99a1e; }
.kr-files-quota.is-full .kr-files-quota-bar > span { background: #c0392b; }
.kr-files-quota.is-full .kr-files-quota-left { color: #c0392b; font-weight: 600; }
