@import url("./fonts/fonts.css");

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* the hidden attribute must win over any display: grid/flex set on the same element */
[hidden] {
  display: none !important;
}

:root {
  --bg: #0b0d12;
  --bg-surface: #12151c;
  --bg-card: #181c25;
  --bg-elevated: #222733;
  --text: #f3f4f6;
  --text-muted: #c4c9d4;
  --text-dim: #9aa3b5;
  --accent: #3b82f6;
  --accent-hover: #5b95f7;
  --accent-text: #8fbcff;
  --accent-glow: rgba(59, 130, 246, 0.16);
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.26);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  --toggle-bg: var(--bg-elevated);
  --pad: 16px;
  --pad-lg: 24px;
  --max-w: 820px;
  --max-w-wide: 1200px;
  /* type scale — use these, never raw px */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-base: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --radius: 12px;
  --radius-sm: 10px;
  --radius-pill: 100px;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-surface: #ffffff;
  --bg-card: #fafafa;
  --bg-elevated: #eceef2;
  --text: #0f172a;
  --text-muted: #334155;
  --text-dim: #5b6577;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.10);
  --border: rgba(15, 23, 42, 0.10);
  --border-hover: rgba(15, 23, 42, 0.20);
  --border-strong: rgba(15, 23, 42, 0.32);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --toggle-bg: var(--bg-elevated);
}

@media (min-width: 1024px) {
  :root { --fs-xs: 13px; --fs-sm: 14px; --fs-md: 16px; --fs-base: 16px; --fs-lg: 20px; --fs-xl: 26px; --fs-2xl: 32px; }
}

/* ═══ SYSTEM ═══ */

/* --- buttons: one shape, four levels --- */
.btn,
.recalculate-btn,
.download-full,
.upload-btn,
.inv-btn,
.header-link,
.save-next-btn,
.link-btn,
.history-clear,
.delete-result-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.btn svg,
.recalculate-btn svg,
.download-full svg,
.upload-btn svg,
.inv-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Primary — one per view section */
.btn-primary,
.recalculate-btn,
.download-full,
.upload-btn.primary,
.inv-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover,
.recalculate-btn:hover,
.download-full:hover,
.upload-btn.primary:hover,
.inv-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Secondary — navigation and alternatives */
.btn-secondary,
.upload-btn.secondary,
.history-clear,
.header-link,
.save-next-btn,
.link-btn {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover,
.history-clear:hover,
.upload-btn.secondary:hover,
.header-link:hover,
.save-next-btn:hover,
.link-btn:hover {
  background: var(--bg-card);
  border-color: var(--border-hover);
}

.header-link.is-current {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Ghost — inline low-emphasis */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Danger — delete only */
.btn-danger,
.delete-result-btn {
  background: transparent;
  border-color: rgba(239, 68, 68, .35);
  color: var(--red);
}

.btn-danger:hover,
.delete-result-btn:hover {
  background: rgba(239, 68, 68, .12);
}

/* Sizes */
.btn-sm,
.header-link,
.save-next-btn,
.history-clear {
  height: 34px;
  padding: 0 16px;
  font-size: var(--fs-sm);
}

.btn-block {
  display: flex;
  width: 100%;
  border-radius: var(--radius);
}

/* --- icon button: 40px circle, secondary look --- */
.icon-btn,
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: none;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.icon-btn:hover,
.theme-toggle:hover {
  background: var(--bg-card);
  border-color: var(--border-hover);
}

/* --- labels: uppercase eyebrow text --- */
.label,
.metric-label,
.notes-label,
.detected-color-label,
.inv-field-label,
.inv-eyebrow,
.table th {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* --- cards: one surface level for tiles, panels, list rows --- */
.card,
.calib-card,
.metric-card,
.notes-section,
.scene-card,
.history-item,
.inv-active,
.inv-empty-card,
.preview-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card {
  padding: 16px;
}

@media (min-width: 700px) {
  .card {
    padding: 20px;
  }
}

/* --- controls: inset surface for inputs/selects/textareas --- */
.control,
.inv-control,
.sticker-size-field input[type="number"],
.notes-input {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hover);
  background: var(--bg-surface);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}

.control:focus-visible,
.inv-control:focus-visible,
.sticker-size-field input[type="number"]:focus-visible,
.notes-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* --- segmented tab control --- */
.shape-tabs,
.view-tabs {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.shape-tab,
.view-tab {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}

.shape-tab:hover,
.view-tab:hover {
  color: var(--text);
}

.shape-tab.active,
.view-tab.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.unit-toggle {
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}

/* --- data table (generic, unmapped) --- */
.table {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table::-webkit-scrollbar {
  height: 6px;
}

.table::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

.table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th,
.table td {
  height: 48px;
  padding: 0 16px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover {
  background: var(--bg-elevated);
}

.table td.num {
  font-family: var(--mono);
  text-align: right;
}

/* --- delta pill (green/red tint) --- */
.delta {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-dim);
}

.delta.delta-pos {
  background: rgba(34, 197, 94, .15);
  color: var(--green);
}

.delta.delta-neg {
  background: rgba(239, 68, 68, .15);
  color: var(--red);
}

/* --- empty state --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
  font-size: var(--fs-md);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  padding: 12px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-dim);
  box-sizing: border-box;
}

.empty-state-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state.empty-state-sm {
  padding: 4px 0 0;
  text-align: left;
}

.empty-state.empty-state-sm p {
  margin-bottom: 10px;
}

/* --- section title: a heavier weight than .label, for section headers --- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}

.section-title .count {
  color: var(--text-dim);
  font-weight: 600;
}

/* --- card weights: filled .card vs transparent .card-muted for containers --- */
.card-muted {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

@media (min-width: 700px) {
  .card-muted {
    padding: 20px;
  }
}

/* --- session card: the one non-button accent surface, for the active setup --- */
.session-card {
  background: var(--accent-glow);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
}

@media (min-width: 700px) {
  .session-card {
    padding: 20px;
  }
}

.session-card .label {
  margin-bottom: 2px;
}

.session-card .session-name {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-card .session-meta {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-top: 2px;
}

.session-card .session-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

/* --- mini row: one recent measurement inside the session card's "Recent" list --- */
.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text);
}

.mini-row:last-child {
  border-bottom: none;
}

.mini-row .mini-row-date {
  color: var(--text-dim);
}

/* --- compare rows: label / A / B / delta grid with a header row --- */
.cmp-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cmp-grid-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--fs-sm);
}

.cmp-grid-row:last-child {
  border-bottom: none;
}

.cmp-grid-row.cmp-grid-head {
  font-family: var(--font);
  color: var(--text-dim);
}

.cmp-grid-row .inv-mono {
  text-align: right;
}

/* --- desktop workbench: two-column layout, work left / context right --- */
.workbench-side {
  display: none;
}

@media (min-width: 1024px) {
  .workbench {
    display: grid;
    grid-template-columns: minmax(0, 62fr) minmax(0, 38fr);
    gap: 24px;
    align-items: start;
  }

  .workbench-main {
    min-width: 0;
  }

  .workbench-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 24px;
    min-width: 0;
  }
}

html,
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  font-size: var(--fs-base);
  line-height: 1.5;
  transition: background .3s, color .3s
}

body {
  display: flex;
  flex-direction: column;
  align-items: center
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring)
}

@media(prefers-reduced-motion:reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important
  }
}

.app {
  width: 100%;
  max-width: var(--max-w);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 var(--pad)
}

@media (min-width: 1024px) {
  .app {
    max-width: var(--max-w-wide);
    padding: 0 var(--pad-lg);
  }
}

@media(min-width:640px) {
  .app {
    padding: 0 var(--pad-lg)
  }
}

/* Header */
header {
  padding: 16px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0
}

.logo {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--text)
}

.logo sup {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-muted);
  vertical-align: top;
  margin-left: 1px
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap
}

.header-link {
  white-space: nowrap
}

.theme-toggle svg {
  transition: transform .3s var(--ease)
}

.theme-toggle:hover svg {
  transform: rotate(15deg)
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: block
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeUp .35s var(--ease) both
}

.screen.active {
  display: flex
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

/* Preview */
.preview-section {
  margin-bottom: 20px
}

.preview-card {
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative
}

.preview-dismiss {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #fff;
  font-size: var(--fs-lg);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .2s var(--ease);
}

.preview-dismiss:hover {
  background: rgba(0, 0, 0, .8);
}

.preview-card img {
  width: 100%;
  display: block
}

[data-theme="dark"] .preview-img-light,
[data-theme="light"] .preview-img-dark {
  display: none;
}

.preview-overlay {
  position: absolute;
  top: 12px;
  left: 12px
}

.preview-badge {
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  letter-spacing: .5px;
  text-transform: uppercase
}

.preview-caption {
  padding: 12px 16px;
  font-size: var(--fs-md);
  color: var(--text-muted);
  text-align: center
}

.preview-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%,
      rgba(0, 0, 0, .65) 0%,
      rgba(0, 0, 0, .45) 25%,
      rgba(0, 0, 0, .15) 55%,
      rgba(0, 0, 0, 0) 80%);
  z-index: 1;
}

.preview-cta {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 18px 34px;
  font-family: inherit;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent, #4f8cff) 0%, #7a3dff 100%);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius-pill, 999px);
  cursor: pointer;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, .5),
    0 0 0 8px rgba(255, 255, 255, .05),
    0 0 60px rgba(122, 61, 255, .45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform .2s var(--ease, ease), box-shadow .2s var(--ease, ease), filter .2s var(--ease, ease);
  white-space: nowrap;
  z-index: 2;
}

.preview-cta:hover {
  transform: translate(-50%, -50%) scale(1.05);
  filter: brightness(1.1);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, .6),
    0 0 0 10px rgba(255, 255, 255, .07),
    0 0 80px rgba(122, 61, 255, .65);
}

.preview-cta:active {
  transform: translate(-50%, -50%) scale(0.98);
}

.preview-cta svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

@media (max-width: 480px) {
  .preview-cta {
    font-size: var(--fs-md);
    padding: 15px 24px;
    gap: 10px;
  }

  .preview-cta svg {
    width: 18px;
    height: 18px;
  }
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .25s var(--ease);
  background: var(--bg-surface)
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow)
}

.upload-zone.dragover {
  transform: scale(1.005)
}

.upload-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--accent)
}

.upload-zone h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: 6px
}

.upload-zone p {
  font-size: var(--fs-md);
  color: var(--text-dim)
}

.upload-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap
}

.sticker-size-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 18px;
}

.sticker-size-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.sticker-size-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-muted);
}

.sticker-size-field>span:first-child {
  min-width: 12px;
}

.sticker-size-field input[type="number"] {
  width: 86px;
  font-family: var(--mono);
  text-align: center;
}

.sticker-size-unit {
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

/* Detected color + calibration card (result & history detail) */
.calib-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 18px 0 14px;
  padding: 16px;
}

.calib-card:empty {
  display: none;
}

.detected-color-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.detected-color-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.detected-color-label {
  letter-spacing: .09em;
}

.color-swatch {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border-hover);
  box-shadow: inset 0 0 0 2px var(--bg-card);
}

.detected-color-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-chip {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  background: var(--bg-elevated);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  white-space: nowrap;
}

.recalculate-row {
  justify-content: flex-start;
  margin-top: 0;
}

.detected-color-block+.recalculate-row {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Narrow screens: label on its own line, the two fields side by side,
   the Recalculate button full width — otherwise W and H wrap apart. */
@media (max-width: 560px) {
  .sticker-size-row {
    gap: 10px;
  }

  .sticker-size-row .sticker-size-label {
    flex: 1 0 100%;
    text-align: center;
  }

  .recalculate-row .sticker-size-label {
    text-align: left;
  }

  .sticker-size-row .sticker-size-field {
    flex: 1 1 0;
    min-width: 0;
  }

  .sticker-size-row .sticker-size-field input[type="number"] {
    width: 100%;
    min-width: 0;
  }

  .recalculate-btn {
    flex: 1 0 100%;
  }
}

.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--red);
  background: rgba(239, 68, 68, .10);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
}

/* Crop Overlay */
.crop-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1100;
  display: none;
  flex-direction: column;
}

.crop-overlay.active {
  display: flex;
}

.crop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.crop-header h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
}

.crop-header p {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

.crop-stage {
  flex: 1;
  min-height: 0;
  background: #000;
  display: flex;
  padding: 28px 20px;
}

.crop-stage-inner {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crop-stage-inner img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Cropper.js clips handles at .cropper-container edges by default; let them
   render into the surrounding padding instead. */
.crop-stage .cropper-container {
  overflow: visible !important;
}

.crop-actions {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.crop-actions button {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .2s var(--ease);
  min-height: 44px;
}

.crop-actions .crop-skip {
  background: var(--bg-card);
  color: var(--text-muted);
}

.crop-actions .crop-skip:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.crop-actions .crop-apply {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(59, 130, 246, .3);
}

.crop-actions .crop-apply:hover {
  background: var(--accent-hover);
}

.crop-sticker-row {
  margin-top: 0;
  padding: 12px 16px 2px;
  flex-shrink: 0;
}

.crop-tools {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  justify-content: center;
  flex-shrink: 0;
}

.crop-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.crop-tool-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Processing Overlay */
.processing-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s
}

.processing-overlay.active {
  opacity: 1;
  pointer-events: auto
}

.spinner-wrap {
  position: relative;
  width: 56px;
  height: 56px
}

.spinner {
  width: 56px;
  height: 56px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite
}

.spinner-pulse {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .08;
  animation: pulse 2s ease-in-out infinite
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(.8);
    opacity: .05
  }

  50% {
    transform: scale(1.2);
    opacity: .12
  }
}

.processing-overlay p {
  font-size: var(--fs-base);
  color: var(--text-muted);
  font-weight: 500
}

/* Result */
.result-header {
  display: flex;
  align-items: center;
  padding: 8px 0 14px;
  gap: 12px;
  flex-shrink: 0
}

.result-header-text {
  flex: 1
}

.result-header-text h2 {
  font-size: var(--fs-lg);
  font-weight: 600
}

.result-header-text p {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-top: 2px
}

.result-actions {
  display: flex;
  gap: 8px
}

.result-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding-bottom: 32px
}

@media(min-width:768px) {
  .result-layout {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: stretch;
  }

  .result-data-panel {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  .result-layout {
    grid-template-columns: minmax(0, 62fr) minmax(0, 38fr);
    align-items: start;
  }

  .result-image-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .result-scene-panel {
    grid-column: 1;
    grid-row: 2;
  }

  .result-data-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    position: sticky;
    top: 24px;
  }
}

.result-image-panel,
.result-scene-panel,
.result-data-panel {
  min-width: 0;
}

.result-data-panel {
  overflow: hidden
}

.result-image-panel {
  display: flex;
  flex-direction: column;
}

.result-image-panel .shape-row {
  margin-top: 12px;
}

.result-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex: 1;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-image-wrap img {
  width: 100%;
  display: block
}

.scene-card {
  overflow: hidden;
  box-shadow: var(--shadow);
  padding: 8px;
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.scene-card .plotly-graph-div {
  width: 100% !important;
}

.result-scene-panel {
  display: flex;
  flex-direction: column;
}

.sb50-card {
  height: auto;
  min-height: 0;
  padding: 8px;
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sb50-card .plotly-graph-div {
  width: 100% !important;
  height: 320px !important;
}

.sb50-hint {
  margin: 8px 0 16px;
  padding-left: 12px;
  border-left: 2px solid var(--amber);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: left;
}

.scene-caption {
  padding: 10px 6px 2px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: center;
}

/* View tabs — mobile only, switch between 2D image and 3D scene */
.view-tabs {
  display: none;
  gap: 6px;
  margin-bottom: 12px;
}

.view-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media(max-width:767px) {
  .view-tabs.has-scene {
    display: flex;
  }

  .result-layout.view-image .result-scene-panel {
    display: none;
  }

  .result-layout.view-scene .result-image-wrap {
    display: none;
  }
}

/* Shape Tabs */
.shape-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.shape-row .shape-tabs {
  flex: 1 1 auto;
}

.shape-tabs {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap
}

.shape-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Metrics */
.metrics {
  padding: 8px 0 0
}

.unit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.unit-toggle input {
  accent-color: var(--accent);
}

.unit-toggle.disabled {
  opacity: .55;
  cursor: not-allowed;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px
}

.metric-grid.cols-1 {
  grid-template-columns: 1fr
}

.metric-card {
  padding: 12px 14px;
  transition: background .15s
}

.metric-card:hover {
  background: var(--bg-elevated)
}

.metric-value {
  font-family: var(--mono);
  font-size: var(--fs-xl);
  font-weight: 600;
  margin-top: 4px;
  color: var(--text);
  word-break: break-all
}

.empty-metric {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: var(--fs-md)
}

/* Notes */
.notes-section {
  margin-top: 16px
}

.notes-input {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  line-height: 1.5
}

.notes-input::placeholder {
  color: var(--text-dim)
}

/* Buttons */
.download-full {
  width: 100%;
  margin-top: 16px;
}

.save-next-btn {
  width: 100%;
  margin-top: 8px
}

.delete-result-btn {
  width: 100%;
  margin-top: 8px
}

/* History */
.history-section {
  margin: 24px 0;
  padding: 20px 20px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex: 1
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px
}

@media(min-width:640px) {
  .history-grid {
    grid-template-columns: repeat(4, 1fr)
  }
}

.history-item {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform .2s var(--ease), box-shadow .2s;
}

.history-item:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow)
}

.history-item:active {
  transform: scale(.97)
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover
}

.history-item .meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 8px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, .85);
  font-weight: 500
}

.history-item .del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: var(--fs-base);
  line-height: 1;
  transition: background .15s
}

.history-item .del-btn:hover {
  background: rgba(239, 68, 68, .8)
}

.history-item:hover .del-btn {
  display: flex
}

@media(hover:none) {
  .history-item .del-btn {
    display: flex
  }
}

.history-hint {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-align: center;
  padding: 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px
}

.history-hint svg {
  opacity: .5;
  flex-shrink: 0
}

/* Instance content sections (1.6.0) — only rendered when instance.json provides data */
.intro-text {
  font-size: var(--fs-base);
  color: var(--text);
  line-height: 1.55;
  margin: 2px 0 20px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  max-width: 600px;
  text-align: left
}

.link-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0
}

@media(max-width:520px) {
  .link-row {
    grid-template-columns: 1fr
  }
}

/* an odd last button (e.g. the calibration download) takes the full row */
.link-row .link-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1
}

.link-btn {
  position: relative;
  height: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 40px 16px 18px;
  border-radius: var(--radius);
  text-align: left;
  white-space: normal;
}

.link-btn:hover {
  transform: translateY(-1px)
}

/* small direction hint top right: ↗ for external links, ↓ for downloads */
.link-btn::after {
  content: "\2197";
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--accent)
}

.link-btn[download]::after {
  content: "\2193"
}

.link-btn-text {
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.45
}

/* The theme background stays; the instance image is only a faint texture on top.
   Dark mode inverts it so a light photo reads as dark with light highlights. */
body.has-bg {
  position: relative;
  z-index: 0   /* own stacking context, so the ::before paints above body's background */
}

body.has-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--instance-bg) center/cover no-repeat;
  filter: blur(6px);
  transform: scale(1.04);   /* hides the blurred edge */
  opacity: .55;
  pointer-events: none
}

[data-theme="dark"] body.has-bg::before {
  filter: blur(6px) invert(1) hue-rotate(180deg);   /* lightness flipped, hues kept */
  opacity: .5
}

/* Footer */
.app-footer {
  display: flex;
  flex-wrap: wrap;   /* 5+ links (instances) must not push the page wider than the phone */
  justify-content: center;
  gap: 16px;
  padding: 24px 0;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  margin-top: auto
}

.footer-link {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: .5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s
}

.footer-link:hover {
  color: var(--text-muted);
  background: var(--bg-card)
}

.footer-counter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: .5px;
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.footer-counter svg {
  opacity: .7;
}

#upload-form,
#camera-input {
  position: fixed;
  top: -9999px;
  left: -9999px
}

::-webkit-scrollbar {
  width: 6px
}

::-webkit-scrollbar-track {
  background: transparent
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 3px
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim)
}

/* ═══ INVENTORY ═══ */

/* --- page shell: breadcrumb, title/eyebrow/sub head --- */
.inv-page {
  width: 100%;
  padding: var(--pad-lg) 0 40px;
}

.inv-breadcrumb {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-bottom: 4px;
}

.inv-breadcrumb a {
  color: var(--text-dim);
  text-decoration: none;
}

.inv-breadcrumb a:hover {
  color: var(--text);
}

.inv-sep {
  margin: 0 6px;
  color: var(--text-dim);
  opacity: .6;
}

.inv-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 4px 0 20px;
}

.inv-page-head-text {
  min-width: 0;
}

.inv-page-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.inv-eyebrow {
  display: block;
  letter-spacing: .09em;
  margin-bottom: 4px;
}

.inv-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.inv-sub {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-top: 4px;
}

.inv-demo-banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: 16px;
}

.inv-empty-card {
  margin-bottom: 20px;
}

.inv-empty-cta {
  max-width: 220px;
  margin: 16px auto 0;
}

/* --- shared field primitives (sheet add-form + result details) --- */
.inv-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 14px;
}

.inv-field {
  min-width: 0;
}

.inv-field-narrow {
  max-width: 120px;
}

.inv-field-label {
  display: block;
  margin-bottom: 6px;
}

.inv-control {
  width: 100%;
}

input[type="number"].inv-control {
  font-family: var(--mono);
}

.inv-control-wrap {
  position: relative;
}

.inv-control-wrap .inv-control {
  padding-right: 44px;
}

.inv-unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  pointer-events: none;
}

.inv-error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--red);
  font-size: var(--fs-sm);
  margin-top: 10px;
}

.inv-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
}

/* --- home: active setup pill (mobile/tablet only — desktop uses the session card in .workbench-side) --- */
.inv-chip-row {
  margin-top: 14px;
}

@media (min-width: 1024px) {
  .inv-chip-row {
    display: none;
  }
}

.inv-active {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  color: inherit;
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.inv-active:hover {
  border-color: var(--border-hover);
  background: var(--bg-elevated);
}

.inv-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.inv-dot.active {
  background: var(--accent);
}

.inv-active-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inv-active-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.inv-active-value {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- inventory card (result, archive, measurement) --- */
.inv-card { margin-bottom: 16px; }
.inv-card-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.inv-card-badge { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg-elevated); color: var(--text-dim); }
.inv-card-badge .inv-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); }
.inv-card.is-saved .inv-card-badge { background: rgba(34, 197, 94, .15); color: var(--green); }
.inv-card-text { flex: 1 1 160px; min-width: 0; }
.inv-card-title { font-size: var(--fs-md); font-weight: 600; color: var(--text); margin-top: 2px; }
.inv-card-title.inv-card-title-lg { font-size: var(--fs-lg); font-weight: 700; }
.inv-card-meta { font-size: var(--fs-sm); color: var(--text-dim); margin-top: 2px; }
.inv-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.inv-card-details { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.inv-fields-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
@media (max-width: 480px) { .inv-fields-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .inv-fields-3 > :last-child { grid-column: 1 / -1; } }
.inv-kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.inv-kv-grid .inv-kv-value { font-family: var(--mono); font-size: var(--fs-md); color: var(--text); margin-top: 2px; }
.inv-kv-grid .inv-unit-hint { color: var(--text-dim); font-size: var(--fs-sm); margin-left: 3px; }

.inv-details-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.inv-details-toggle .inv-chevron {
  margin-left: auto;
  transition: transform .2s var(--ease);
}

.inv-details-toggle.open .inv-chevron {
  transform: rotate(180deg);
}

.inv-save-state {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-weight: 500;
}

/* --- native <dialog> setup sheet (_inventory_sheet.html) --- */
.inv-sheet {
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  max-width: min(560px, 92vw);
  width: 100%;
  margin: auto;
}

.inv-sheet::backdrop {
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
}

.inv-sheet-inner {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  max-height: 88vh;
  overflow: auto;
}

.inv-sheet-inner:focus {
  outline: none;
  box-shadow: none;
}

.inv-sheet-handle {
  display: none;
}

.inv-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.inv-sheet-title {
  font-size: var(--fs-lg);
  font-weight: 600;
}

@media (max-width: 700px) {
  .inv-sheet {
    max-width: 100%;
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    margin: 0;
  }

  .inv-sheet-inner {
    border-radius: 20px 20px 0 0;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    animation: inv-sheet-up .26s var(--ease);
  }

  .inv-sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-hover);
    margin: 0 auto 14px;
  }
}

@keyframes inv-sheet-up {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

/* --- setup picker list (inside the sheet) --- */
.inv-pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.inv-pick-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.inv-pick-row:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.inv-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-hover);
  flex-shrink: 0;
  position: relative;
}

.inv-pick-row[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.inv-pick-row[aria-checked="true"] .inv-radio {
  border-color: var(--accent);
  background: var(--accent);
}

.inv-pick-row[aria-checked="true"] .inv-radio::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
}

.inv-pick-main {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-pick-meta {
  flex-shrink: 0;
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.inv-add-form {
  margin-top: 12px;
}

.inv-add-form .inv-fields {
  align-items: end;
}

.inv-empty-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  padding: 8px 0 4px;
}

/* --- setup list (inventory_guns.html) --- */
.inv-setup-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 700px) {
  .inv-setup-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (min-width: 1024px) {
  .inv-setup-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

.inv-setup-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 136px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s;
  min-width: 0;
}

.inv-setup-card:hover {
  border-color: var(--border-hover);
}

.inv-setup-card.is-empty {
  color: var(--text-dim);
}

.inv-setup-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.inv-setup-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.inv-setup-name {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 1024px) {
  .inv-setup-name {
    font-size: var(--fs-lg);
    font-weight: 700;
  }
}

.inv-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent-text);
}

.inv-setup-meta {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-setup-stat {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.inv-setup-width {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
}

.inv-setup-stat-empty {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

/* --- nozzle timeline charts (inventory_nozzle.html) --- */
.inv-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px 12px;
  margin-bottom: 14px;
}

.inv-chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.inv-chart-unit-hint {
  font: 500 var(--fs-xs)/1 var(--mono);
  color: var(--text-dim);
  display: block;
  text-align: right;
}

.inv-chart-plot { position: relative; height: 200px; margin: 8px 6px 26px 60px; padding: 0; }
@media (min-width: 1024px) { .inv-chart-plot { height: 240px; } }
.inv-chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.inv-chart-grid { stroke: currentColor; color: var(--text-dim); opacity: .12; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.inv-chart-line { stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; fill: none; vector-effect: non-scaling-stroke; }
.inv-chart-area { stroke: none; }
.inv-chart-point { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg-card); transform: translate(-50%, -50%); transition: transform 150ms var(--ease); }
.inv-chart-point:hover { transform: translate(-50%, -50%) scale(1.3); }
.inv-chart-ytick { position: absolute; right: calc(100% + 10px); transform: translateY(-50%); font: 500 var(--fs-xs)/1 var(--mono); color: var(--text-dim); white-space: nowrap; }
.inv-chart-xtick { position: absolute; top: calc(100% + 8px); font: 500 var(--fs-xs)/1 var(--mono); color: var(--text-dim); white-space: nowrap; }
.inv-chart-xtick.is-start { transform: none; } .inv-chart-xtick.is-middle { transform: translateX(-50%); } .inv-chart-xtick.is-end { transform: translateX(-100%); }
@media (max-width: 480px) { .inv-chart-xtick.is-middle { display: none; } }

.inv-mono {
  font-family: var(--mono);
}

.inv-swatch {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-hover);
  flex-shrink: 0;
}

.inv-swatch-lg {
  width: 44px;
  height: 44px;
}

.inv-swatch-cmp {
  width: 28px;
  height: 28px;
}

.inv-unit-hint {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-left: 4px;
}

.inv-orig-link {
  display: inline-block;
  margin-top: 8px;
  font-size: var(--fs-sm);
  color: var(--accent);
  text-decoration: none;
}

.inv-orig-link:hover {
  text-decoration: underline;
}

.inv-siblings {
  margin-top: 14px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.inv-siblings a {
  color: var(--accent);
}

.delta-pos {
  color: var(--green);
}

.delta-neg {
  color: var(--red);
}

/* ═══ INVENTORY: NOZZLE PAGE ═══ */

/* --- nozzle summary card (workbench-side) --- */
.inv-summary-key {
  font-family: var(--mono);
  font-size: var(--fs-2xl);
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

.inv-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.inv-summary-val {
  font-family: var(--mono);
  font-size: var(--fs-md);
  color: var(--text);
  margin-top: 4px;
}

@media (max-width: 1023px) {
  .workbench-side-first {
    display: flex;
    flex-direction: column;
  }

  .workbench-side-first .workbench-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    order: -1;
    margin-bottom: 16px;
  }
}

/* --- nozzle desktop grid: chart/list-head/compare/list are explicit rows in the
   main column; compare spans both columns (full width) when it has content;
   the summary card spans the same row range in the side column --- */
@media (min-width: 1024px) {
  .workbench-side-first {
    row-gap: 0;
  }

  .workbench-side-first > .inv-chart-card {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    margin-bottom: 0;
  }

  .workbench-side-first > .inv-list-head {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }

  .workbench-side-first > #compare-slot-main {
    grid-column: 1 / -1;
    grid-row: 3;
    min-width: 0;
  }

  .workbench-side-first > .inv-mrow-list,
  .workbench-side-first > .inv-empty-card {
    grid-column: 1;
    grid-row: 4;
    min-width: 0;
  }

  .workbench-side-first > .workbench-side {
    grid-column: 2;
    grid-row: 1 / 5;
  }
}

/* --- chart card: metric panels (base .inv-chart-card/.inv-chart-head/.inv-chart-svg
   etc. already exist in styles.css) --- */
.inv-chart-hint {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-family: var(--mono);
  margin: 0 0 4px;
}

/* --- measurement list header --- */
.inv-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 24px 0 12px;
}

.inv-list-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- measurement rows --- */
.inv-mrow-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inv-mrow {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.inv-mrow:hover {
  border-color: var(--border-hover);
}

.inv-mrow.is-selected {
  border-left: 3px solid var(--accent);
  background: var(--accent-glow);
  padding-left: 17px;
}

.inv-mrow.is-selected .inv-radio {
  border-color: var(--accent);
  background: var(--accent);
}

.inv-mrow.is-selected .inv-radio::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
}

.inv-mrow-body {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.inv-mrow-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.inv-mrow-date {
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 600;
}

.inv-mrow-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.inv-mrow-setup {
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.inv-mrow-nums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  margin-left: auto;
  text-align: right;
  flex-shrink: 0;
}

.inv-mrow-dims {
  font-family: var(--mono);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.inv-mrow-area {
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.inv-mrow-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 480px) {
  .inv-mrow {
    grid-template-columns: 1fr auto;
  }

  .inv-mrow-body {
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  .inv-mrow-nums {
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
    margin-left: 0;
    flex-basis: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    min-width: 0;
  }

  .inv-mrow-dims {
    font-size: var(--fs-md);
  }
}

/* --- inline compare card --- */
.inv-compare-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 10px;
  max-height: 2000px;
  opacity: 1;
  overflow: hidden;
  transition: max-height .2s var(--ease), opacity .2s var(--ease), padding .2s var(--ease), margin .2s var(--ease);
}

.inv-compare-card.is-collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  border-width: 0;
  display: block;
  visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .inv-compare-card {
    transition: none;
  }
}

/* full width, images left half + metric table right half, one row on desktop */
.inv-compare-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 1024px) {
  .inv-compare-body {
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
  }

  .inv-compare-images {
    flex: 1 1 50%;
    min-width: 0;
    margin-bottom: 0;
  }

  .inv-compare-rows {
    flex: 1 1 50%;
    min-width: 0;
  }
}

.inv-compare-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.inv-compare-fig {
  margin: 0;
}

.inv-compare-fig img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hover);
  display: block;
}

.inv-compare-fig figcaption {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-bottom: 6px;
  font-family: var(--mono);
}

@media (max-width: 480px) {
  .inv-compare-images {
    grid-template-columns: 1fr;
  }
}

.inv-compare-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

