:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #737373;
  --faint: #a3a3a3;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --surface: #fafafa;
  --surface-hover: #f5f5f5;
  --danger: #dc2626;
  --radius: 6px;
  --shadow-lg: 0 20px 50px rgba(10, 10, 10, 0.18);
}

* {
  box-sizing: border-box;
}

html, body {
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 200px;
  padding: 1rem 0.625rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 80;
  transition: width 0.18s ease, padding 0.18s ease;
}

.sidebar .brand {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  padding: 0.35rem 0.75rem 1rem;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.1s, color 0.1s;
}

.sidebar-nav a svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.sidebar-nav a:hover {
  background: var(--surface-hover);
  color: var(--fg);
}

.sidebar-nav a.active {
  background: var(--fg);
  color: var(--bg);
}

.sidebar-toggle {
  position: absolute;
  top: 0.6rem;
  right: 0.5rem;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--faint);
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
}

.sidebar-toggle:hover {
  background: var(--surface-hover);
  color: var(--fg);
}

.sidebar-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.18s;
}

/* Collapsed sidebar */
.sidebar.collapsed {
  width: 52px;
  padding: 1rem 0.3rem;
}

.sidebar.collapsed .brand {
  visibility: hidden;
  height: 0;
  padding: 0;
  margin-bottom: 2.25rem;
}

.sidebar.collapsed .sidebar-nav a,
.sidebar.collapsed .sidebar-logout button {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .sidebar-nav a > span,
.sidebar.collapsed .sidebar-logout button > span,
.sidebar.collapsed .sidebar-user {
  display: none;
}

.sidebar.collapsed .sidebar-toggle {
  right: 50%;
  transform: translateX(50%);
}

.sidebar.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

.sidebar-logout {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sidebar-logout form {
  margin: 0;
}

.sidebar-logout button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  border: none;
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.sidebar-logout button:hover {
  background: var(--surface-hover);
  color: var(--fg);
}

.sidebar-logout svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.sidebar-user {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  padding: 0 0.75rem 0.35rem;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  min-height: 100vh;
  margin: 0;
  background: var(--surface);
}

.login-main {
  width: 100%;
  max-width: 340px;
}

.login-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.75rem;
  box-shadow: 0 4px 24px rgba(10, 10, 10, 0.06);
}

.login-brand {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  margin-bottom: 1.25rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.login-form label {
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
}

.login-form input[type=text],
.login-form input[type=password] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

.login-form input:focus {
  outline: none;
  border-color: var(--fg);
}

.login-form button.primary {
  margin-top: 1rem;
}

.login-note {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.login-error {
  padding: 0.5rem 0.7rem;
  font-size: 0.8rem;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  margin-bottom: 0.25rem;
}

/* Accounts */
.accounts-main {
  max-width: 1040px;
  height: 100vh;
}

.accounts-page {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.account-create {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(0, 1.25fr);
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 1rem;
}

.account-create h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.account-create p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.account-form input[type=email],
.account-form input[type=password] {
  width: 100%;
  height: 2.3rem;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

.account-form input:focus {
  outline: none;
  border-color: var(--fg);
}

.account-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
}

.account-check input {
  margin: 0;
}

.account-success {
  padding: 0.5rem 0.7rem;
  color: #166534;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  font-size: 0.8rem;
}

.account-list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.account-table {
  min-width: 720px;
}

/* Stats */
.stats-main {
  max-width: 1120px;
  height: 100vh;
}

.stats-page {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stats-card {
  min-height: 5rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stats-card span,
.stats-panel h2,
.stats-recent h2 {
  margin: 0;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-card strong {
  color: var(--fg);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0;
}

.stats-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stats-panel,
.stats-recent {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.stats-panel h2,
.stats-recent h2 {
  padding: 0.75rem 0.75rem 0.6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.stats-table {
  min-width: 0;
  table-layout: auto;
}

.stats-table th,
.stats-table td {
  white-space: nowrap;
}

.stats-recent {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stats-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.stats-recent-table {
  min-width: 980px;
}

.status-failed {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.status-partial {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* Model tools */
.model-tools-main {
  max-width: 1120px;
  height: 100vh;
}

.model-tools-page {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.model-tool-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.model-tool-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.model-tool-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.model-tool-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.model-tool-meta,
.model-tool-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.model-tool-meta {
  flex-wrap: wrap;
  color: var(--faint);
  font-size: 0.76rem;
}

.model-tool-actions {
  flex: 0 0 auto;
}

.model-tool-actions form {
  margin: 0;
}

.model-measurements {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  border-bottom: 1px solid var(--border);
}

.model-measurements div {
  min-width: 0;
  padding: 0.75rem 1rem;
  border-right: 1px solid var(--border);
}

.model-measurements div:last-child {
  border-right: 0;
}

.model-measurements dt {
  margin: 0 0 0.2rem;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.model-measurements dd {
  margin: 0;
  color: var(--fg);
  font-weight: 600;
}

.model-bucket-assets {
  padding: 0.85rem 1rem 1rem;
}

.model-section-label {
  margin-bottom: 0.6rem;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.model-asset-row {
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: thin;
}

.model-asset-card {
  flex: 0 0 132px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
}

.model-asset-card:hover {
  border-color: var(--border-strong);
}

.model-asset-card img {
  width: 100%;
  aspect-ratio: 3/4;
  display: block;
  object-fit: contain;
  background: var(--bg);
}

.model-asset-card span,
.model-asset-card small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-asset-card span {
  padding: 0.45rem 0.5rem 0.1rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.model-asset-card small {
  padding: 0 0.5rem 0.45rem;
  color: var(--faint);
  font-size: 0.65rem;
}

.model-empty,
.model-empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.model-empty-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.model-empty-state p {
  margin: 0;
}

.model-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.model-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.model-form-actions .primary,
.model-form-actions .toolbar-button {
  width: auto;
  min-width: 8rem;
}

.row + .row {
  margin-top: 0.85rem;
}

#form > .row {
  flex: 0 0 auto;
}

#form > #results-section {
  flex: 1 1 auto;
}

.row-pair {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 0.75rem;
}

.row-pair .field {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.row-pair .field > :last-child {
  margin-top: auto;
}

label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin-bottom: 0.35rem;
}

label .muted-suffix {
  color: var(--faint);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

/* Pose selector button (opens modal) */
.select-button {
  width: 100%;
  height: 2.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--fg);
  text-align: left;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

.select-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.select-button:focus-visible {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.select-button .select-button-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-button .value {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.select-button .chevron {
  color: var(--faint);
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

/* Drop zone */
#dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.12s, background 0.12s;
}

#dropzone:hover {
  border-color: var(--faint);
  background: var(--surface-hover);
}

#dropzone.dragover {
  border-color: var(--fg);
  background: var(--surface-hover);
}

#dropzone p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

#preview-wrap {
  display: none;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
}

#preview-wrap.visible {
  display: flex;
}

.ref-list {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
}

.ref-item {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ref-item img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.ref-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#preview-wrap .ref-remove {
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--faint);
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

#preview-wrap .ref-remove svg {
  width: 0.9rem;
  height: 0.9rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#preview-wrap .ref-remove:hover {
  background: var(--bg);
  border-color: var(--border);
  color: var(--danger);
}

#preview-wrap > button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--muted);
}

#preview-wrap > button:hover {
  border-color: var(--fg);
  color: var(--fg);
}

textarea {
  width: 100%;
  min-height: 44px;
  height: 44px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  background: var(--bg);
  color: var(--fg);
}

textarea::placeholder {
  color: var(--faint);
}

textarea:focus {
  outline: none;
  border-color: var(--fg);
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.compact-measurement-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.measurement-field > span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 600;
}

.measurement-input {
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
}

.measurement-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
}

.measurement-input input:focus {
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: none;
}

input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button,
input[type=search]::-webkit-search-results-button,
input[type=search]::-webkit-search-results-decoration {
  display: none;
  -webkit-appearance: none;
}

button.primary {
  width: 100%;
  padding: 0.55rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--fg);
  color: var(--bg);
  border: 1px solid var(--fg);
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.12s;
}

button.primary:hover {
  opacity: 0.88;
}

button.primary:disabled {
  opacity: 0.4;
  cursor: wait;
}

#status {
  margin-top: 0.6rem;
  min-height: 1.1rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

#status.error {
  color: var(--danger);
}

/* Results */
#results-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#results-section > label {
  flex: 0 0 auto;
}

.results {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.35rem;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

.card {
  flex: 0 0 calc((100% - 1rem) / 3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  scroll-snap-align: start;
}

.card img {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  background: var(--surface);
  object-fit: contain;
}

.card-footer {
  flex: 0 0 auto;
}

.card-placeholder {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  align-items: center;
  justify-content: center;
  color: var(--faint);
}

.card-placeholder svg {
  width: 2.25rem;
  height: 2.25rem;
  opacity: 0.8;
}

.card-footer {
  padding: 0.5rem 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-footer a {
  color: var(--fg);
  text-decoration: none;
}

.card-footer a:hover {
  text-decoration: underline;
}

.card-err {
  padding: 1.25rem 0.75rem;
  text-align: center;
  color: var(--danger);
  font-size: 0.8rem;
}

#form .results {
  flex: 0 0 auto;
  align-items: start;
}

#form .card {
  align-self: start;
}

#form .card img,
#form .card-placeholder {
  aspect-ratio: 3/4;
}

#form .card img {
  flex: 0 0 auto;
  height: auto;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
  animation: fade 0.12s ease-out;
}

.modal.open {
  display: flex;
}

.modal-dialog {
  background: var(--bg);
  border-radius: 10px;
  width: 100%;
  max-width: 820px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 0.14s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--surface);
  color: var(--fg);
}

.modal-close svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-footer button {
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.85rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.modal-footer .secondary {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
}

.modal-footer .secondary:hover {
  border-color: var(--fg);
}

.modal-footer .primary {
  width: auto;
  padding: 0.5rem 1.25rem;
}

.shopify-fetch-dialog {
  max-width: 420px;
}

.shopify-fetch-form select {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.45rem 0.65rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
}

/* Pose picker (inside modal) */
.poses {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
}

.poses figure {
  margin: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, background 0.12s;
}

.poses figure:hover {
  border-color: var(--faint);
}

.poses figure.selected {
  border-color: var(--fg);
}

.poses figure.selected figcaption {
  color: var(--fg);
}

.poses figure:not(.selected) img {
  opacity: 0.35;
}

.poses img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: contain;
  display: block;
  transition: opacity 0.12s;
}

.poses figcaption {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
/* Segmented control (model picker) */
.segment-control {
  display: inline-flex;
  width: 100%;
  height: 2.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  padding: 2px;
  gap: 2px;
}

.segment {
  flex: 1;
  min-width: 0;
  padding: 0 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: calc(var(--radius) - 2px);
  transition: background 0.12s, color 0.12s;
}

.segment:hover {
  color: var(--fg);
}

.segment.active {
  background: var(--fg);
  color: var(--bg);
}

/* Custom select (listbox) */
.custom-select {
  position: relative;
}

.custom-select[data-open=true] > .custom-select-trigger {
  border-color: var(--fg);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.custom-select[data-open=true] .chevron {
  transform: rotate(180deg);
}

.custom-select-trigger .chevron {
  transition: transform 0.12s;
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(10, 10, 10, 0.12);
  max-height: 12rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  animation: pop 0.1s ease-out;
}

.custom-select-menu::-webkit-scrollbar {
  width: 0.35rem;
}

.custom-select-menu::-webkit-scrollbar-track {
  background: transparent;
}

.custom-select-menu::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.custom-select-menu::-webkit-scrollbar-thumb:hover {
  background: var(--faint);
}

.custom-select-menu[hidden] {
  display: none;
}

.custom-select-option {
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  color: var(--fg);
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background 0.08s, color 0.08s;
  outline: none;
}

.custom-select-option:hover,
.custom-select-option:focus {
  background: var(--surface-hover);
}

.custom-select-option[aria-selected=true] {
  background: var(--fg);
  color: var(--bg);
}

.custom-select-option[aria-selected=true]:hover,
.custom-select-option[aria-selected=true]:focus {
  background: var(--fg);
  color: var(--bg);
  opacity: 0.92;
}

/* Collection badge */
.collection-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* Nav */
/* Save panel (index page, after results) */
.save-panel {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
  flex: 0 0 auto;
  transition: opacity 0.12s;
}

.save-panel.disabled {
  opacity: 0.55;
}

.save-panel > label {
  margin-bottom: 0.3rem;
}

.save-row {
  display: flex;
  gap: 0.5rem;
}

.save-row input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}

.save-row input:focus {
  outline: none;
  border-color: var(--fg);
}

.save-row input:disabled {
  background: var(--surface);
  color: var(--faint);
  cursor: not-allowed;
}

.save-row button.primary {
  width: auto;
  padding: 0.5rem 1.25rem;
}

#save-status {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.1rem;
}

#save-status.error {
  color: var(--danger);
}

#save-status a {
  color: var(--fg);
}

/* Library (products list) */
.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 3rem;
  font-size: 0.9rem;
}

.empty a {
  color: var(--fg);
}

.library-main {
  max-width: 1040px;
  height: 100vh;
}

.product-index {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.product-index-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.product-index-toolbar h1 {
  flex: 0 0 auto;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0;
}

.toolbar-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 2rem;
  padding: 0 0.75rem;
  background: var(--fg);
  border: 1px solid var(--fg);
  border-radius: var(--radius);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  flex: 0 0 auto;
  cursor: pointer;
}

.toolbar-button[type=submit] {
  font: inherit;
}

.toolbar-button:hover {
  opacity: 0.88;
}

.toolbar-button.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
}

.toolbar-button:disabled,
.toolbar-button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.product-search {
  flex: 1 1 420px;
  width: auto;
  max-width: 460px;
  height: 2.25rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.product-search:focus-within {
  background: var(--bg);
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.product-search svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.product-search input {
  min-width: 0;
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
}

.product-search input::placeholder {
  color: var(--faint);
}

.product-results {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.product-section-list {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
  padding-right: 0.15rem;
}

.product-state-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.15rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.product-state-tabs a {
  min-height: 2.1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.product-state-tabs a span {
  white-space: nowrap;
}

.product-state-tabs a:hover {
  background: var(--surface);
  color: var(--fg);
}

.product-state-tabs a.active {
  background: var(--bg);
  border-color: var(--border-strong);
  color: var(--fg);
}

.product-state-tabs strong {
  min-width: 1.28rem;
  height: 1.28rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.product-state-tabs a.active strong {
  background: var(--fg);
  color: var(--bg);
}

.product-state-section {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.product-state-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.product-state-heading h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0;
}

.product-state-heading > div {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

.product-state-heading > div > span {
  color: var(--faint);
  font-size: 0.78rem;
  white-space: nowrap;
}

.product-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100vh - 15.5rem);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.product-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  table-layout: fixed;
}

.product-table th,
.product-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.product-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.product-table td {
  color: var(--muted);
  font-size: 0.85rem;
}

.product-table tbody tr:hover {
  background: var(--surface);
}

.product-table tbody tr:last-child td {
  border-bottom: none;
}

.table-empty {
  height: 8rem;
  text-align: center !important;
  color: var(--muted);
}

.select-col {
  width: 42px;
}

.product-table th:nth-child(2),
.product-table td:nth-child(2) {
  width: auto;
}

.product-table th:nth-child(3),
.product-table td:nth-child(3) {
  width: 138px;
}

.product-table th:nth-child(4),
.product-table td:nth-child(4) {
  width: 92px;
}

.actions-col {
  width: 92px;
  text-align: right;
  padding-right: 0.5rem !important;
}

.actions-col form {
  margin: 0;
  display: inline-flex;
}

.actions-col {
  white-space: nowrap;
}

.table-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  min-width: 4.25rem;
  vertical-align: middle;
}

.table-actions .icon-button {
  margin: 0;
}

.checkbox-box {
  width: 1rem;
  height: 1rem;
  display: inline-block;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  vertical-align: middle;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
}

.product-cell:hover .product-name {
  text-decoration: underline;
}

.product-name-link,
.product-local-link {
  text-decoration: none;
}

.product-name-link:hover,
.product-local-link:hover {
  text-decoration: underline;
}

.product-thumb-stack {
  width: 34px;
  height: 42px;
  flex: 0 0 34px;
  display: block;
}

.product-thumb-stack img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  display: block;
}

.product-thumb-stack:empty {
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
}

.product-cell-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.product-name-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.product-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--fg);
}

.product-external-link {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  border-radius: 4px;
}

.product-external-link:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

.product-external-link svg {
  width: 0.85rem;
  height: 0.85rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.product-subtitle,
.muted-table-text {
  color: var(--faint);
}

.product-upload-status {
  display: none;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
}

.product-upload-status.is-visible {
  display: block;
}

.product-upload-meter {
  width: min(11rem, 100%);
  height: 0.28rem;
  display: none;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface);
}

.product-upload-meter.is-visible {
  display: block;
}

.product-upload-meter span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: var(--fg);
  transition: width 160ms ease;
}

.product-upload-meter.is-indeterminate span {
  width: 42% !important;
  animation: upload-saving 1.05s ease-in-out infinite;
}

@keyframes upload-saving {
  0% {
    transform: translateX(-115%);
  }
  100% {
    transform: translateX(250%);
  }
}
.mobile-hide-col {
  display: table-cell;
}

.toast-region {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.upload-toast {
  max-width: min(22rem, 100vw - 2rem);
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--fg);
  color: var(--bg);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(10, 10, 10, 0.16);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.upload-toast.error {
  background: #8f1d1d;
}

.upload-toast.is-hiding {
  opacity: 0;
  transform: translateY(0.35rem);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  min-height: 1.45rem;
  padding: 0 0.58rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--muted);
}

.status-no-reference {
  background: #fff7f7;
  border-color: #f3c7c7;
  color: #8f1d1d;
}

.status-no-reference::before {
  background: #dc2626;
}

.status-has-reference {
  background: #f6f9ff;
  border-color: #c8d8f5;
  color: #214f94;
}

.status-has-reference::before {
  background: #2563eb;
}

.status-review {
  background: #fffaf0;
  border-color: #efd99a;
  color: #7a4b08;
}

.status-review::before {
  background: #d97706;
}

.status-added {
  background: #f4fbf6;
  border-color: #bfe2c8;
  color: #1f6b35;
}

.status-added::before {
  background: #16a34a;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.product-pagination {
  flex: 0 0 auto;
  min-height: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.pagination-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pagination-actions a,
.pagination-actions > span:not(:nth-child(2)) {
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--bg);
}

.pagination-actions a:hover {
  color: var(--fg);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.pagination-actions > span:not(:nth-child(2)) {
  opacity: 0.45;
}

.pagination-actions svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  flex: 0 0 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0;
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--faint);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  text-decoration: none;
  vertical-align: middle;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.icon-button svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  background: var(--surface-hover);
  border-color: var(--border);
  color: var(--fg);
}

.icon-button:focus-visible {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.icon-button.danger-icon:hover,
.icon-button.danger-icon:focus-visible {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.product-images {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.product-images figure {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
}

.product-images figure.ref-thumb {
  border-color: var(--border-strong);
  background: var(--bg);
}

.product-images img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
}

.product-images figcaption {
  padding: 0.25rem 0.5rem;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
}

/* Product detail */
.product-detail-main {
  max-width: 720px;
  height: 100vh;
}

.product-detail {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.detail-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.detail-heading form {
  margin: 0;
  flex: 0 0 auto;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.detail-actions .toolbar-button,
.detail-actions .icon-button {
  height: 2rem;
}

.detail-actions form {
  margin: 0;
  display: inline-flex;
}

.state-inline-form {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.state-select {
  width: 8.75rem;
}

.state-select .select-button {
  height: 2rem;
  min-height: 2rem;
  padding-inline: 0.55rem;
  font-size: 0.78rem;
}

.state-select .custom-select-menu {
  min-width: 9rem;
}

.detail-heading-copy {
  min-width: 0;
}

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

.detail-back:hover {
  color: var(--fg);
}

.detail-back svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detail-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.detail-title span {
  min-width: 0;
}

.detail-external-link {
  width: 1.35rem;
  height: 1.35rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  margin-top: 0.3rem;
  color: var(--faint);
  font-size: 0.78rem;
}

.detail-meta .status-pill {
  min-height: 1.35rem;
  padding-inline: 0.52rem;
  font-size: 0.64rem;
}

.workflow-form,
.reference-upload {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.workflow-form input[type=text],
.workflow-form input[type=number],
.workflow-form select,
.workflow-form input[type=file],
.reference-upload input[type=file] {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.45rem 0.65rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
}

.workflow-form input[type=file],
.reference-upload input[type=file] {
  padding: 0.28rem;
  color: var(--muted);
  cursor: pointer;
}

.workflow-form input[type=file]::file-selector-button,
.reference-upload input[type=file]::file-selector-button {
  min-height: 1.7rem;
  margin-right: 0.65rem;
  padding: 0 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) - 1px);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.workflow-form input[type=file]::file-selector-button:hover,
.reference-upload input[type=file]::file-selector-button:hover {
  background: var(--surface-hover);
}

.workflow-form input:focus,
.workflow-form select:focus,
.reference-upload input:focus {
  outline: none;
  border-color: var(--fg);
}

input:focus,
select:focus,
textarea:focus {
  outline: none !important;
  border-color: var(--border) !important;
  box-shadow: none !important;
}

.product-search:focus-within {
  border-color: var(--border);
  box-shadow: none;
}

.workflow-form button.primary {
  margin-top: 0.25rem;
}

.reference-upload {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  gap: 0.45rem;
}

.reference-upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.capture-detail {
  max-width: 760px;
}

.capture-form {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.capture-form > input[type=file] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.capture-drop {
  min-height: 10rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}

.capture-drop:hover {
  background: var(--surface-hover);
}

.capture-drop svg {
  width: 2rem;
  height: 2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.capture-drop span {
  font-size: 0.92rem;
  font-weight: 600;
}

.capture-preview {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.65rem;
}

.capture-preview:empty {
  display: none;
}

.capture-preview-card {
  position: relative;
  aspect-ratio: 3/4;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.capture-preview-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.capture-preview-card .icon-button {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  background: rgba(255, 255, 255, 0.92);
}

.capture-actions {
  display: flex;
  align-items: center;
  justify-content: stretch;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

.capture-actions .toolbar-button {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  height: 2.25rem;
  min-height: 2.25rem;
  margin: 0;
  padding: 0 0.85rem;
  font-size: 0.9rem;
  line-height: 1;
  appearance: none;
}

.detail-section {
  min-height: 0;
  min-width: 0;
}

.detail-section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.detail-section-heading h2 {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}

.detail-section-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.detail-image-grid {
  display: flex;
  gap: 0.75rem;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.05rem 0.05rem 0.55rem;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  -webkit-overflow-scrolling: touch;
}

.detail-image-grid::-webkit-scrollbar {
  height: 0.45rem;
}

.detail-image-grid::-webkit-scrollbar-track {
  background: transparent;
}

.detail-image-grid::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.detail-image-card {
  flex: 0 0 clamp(168px, 23vw, 210px);
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
  display: flex;
  flex-direction: column;
  scroll-snap-align: start;
  transition: border-color 0.12s ease;
}

.detail-image-card:hover {
  border-color: var(--border-strong);
}

.detail-image-card img {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
  background: var(--bg);
}

.detail-image-footer {
  min-height: 2.45rem;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.detail-image-footer span,
.detail-image-footer a,
.detail-image-footer {
  min-width: 0;
}

.detail-image-footer span,
.detail-ref .detail-image-footer {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-image-footer a {
  flex: 0 0 auto;
  color: var(--fg);
  text-decoration: none;
}

.detail-image-footer a:hover {
  text-decoration: underline;
}

.detail-image-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.detail-image-actions form,
.detail-image-footer form {
  margin: 0;
}

.detail-image-footer .icon-button {
  width: 1.55rem;
  height: 1.55rem;
}

.detail-image-footer .icon-button svg {
  width: 0.82rem;
  height: 0.82rem;
}

.detail-empty {
  flex: 1 0 100%;
  margin: 0;
  padding: 1.25rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
  font-size: 0.85rem;
}

/* Hover magnifier */
#magnifier {
  position: fixed;
  top: 50%;
  right: 1.5rem;
  transform: translateY(-50%);
  width: min(36vw, 480px);
  aspect-ratio: 3/4;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface) 0 0/auto no-repeat;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  pointer-events: none;
  animation: fade 0.12s ease-out;
}

#magnifier[hidden] {
  display: none;
}

@media (max-width: 960px) {
  #magnifier {
    display: none !important;
  }
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stats-panels {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 720px) {
  body {
    padding-top: 48px;
  }
  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }
  input:focus,
  select:focus,
  textarea:focus {
    outline: none;
    border-color: var(--border);
    box-shadow: none;
  }
  .product-search:focus-within {
    border-color: var(--border);
    box-shadow: none;
  }
  .select-button:focus-visible,
  .icon-button:focus-visible {
    outline: none;
    box-shadow: none;
  }
  .sidebar,
  .sidebar.collapsed {
    flex-direction: row;
    width: 100%;
    height: 48px;
    bottom: auto;
    padding: 0.35rem 0;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
  }
  .sidebar .brand,
  .sidebar.collapsed .brand,
  .sidebar-logout,
  .sidebar.collapsed .sidebar-logout {
    display: none;
  }
  .sidebar-nav,
  .sidebar.collapsed .sidebar-nav {
    flex-direction: row;
    gap: 0.15rem;
    flex: 1;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0.5rem;
    margin: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-nav::-webkit-scrollbar,
  .sidebar.collapsed .sidebar-nav::-webkit-scrollbar {
    display: none;
  }
  .sidebar-nav a,
  .sidebar.collapsed .sidebar-nav a {
    flex: 0 0 auto;
    padding: 0.45rem 0.65rem;
    justify-content: flex-start;
  }
  .sidebar-nav a > span,
  .sidebar.collapsed .sidebar-nav a > span {
    display: inline;
  }
  .sidebar-toggle {
    display: none;
  }
  main {
    padding: 1rem 1rem;
  }
  .product-index-toolbar {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .library-main {
    max-width: none;
  }
  .product-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin: 0;
  }
  .product-state-tabs {
    width: calc(100vw - 2rem);
    margin-inline: 0;
    padding-bottom: 0.35rem;
  }
  .product-state-tabs a {
    min-height: 2rem;
    padding-inline: 0.65rem;
    font-size: 0.78rem;
  }
  .product-state-heading {
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 0.2rem;
  }
  .product-state-heading > div {
    min-width: max-content;
  }
  .product-state-heading .status-pill {
    flex: 0 0 auto;
  }
  .product-table-wrap {
    max-height: calc(100vh - 16.5rem);
  }
  .product-table {
    min-width: 0;
    table-layout: auto;
  }
  .product-table th,
  .product-table td {
    padding: 0.55rem 0.5rem;
  }
  .product-table th.mobile-hide-col,
  .product-table td.mobile-hide-col,
  .product-table .select-col {
    display: none;
  }
  .product-table th:nth-child(2),
  .product-table td:nth-child(2) {
    width: auto;
  }
  .product-table .actions-col {
    width: 5.75rem;
    padding-right: 0.4rem !important;
  }
  .product-thumb-stack {
    display: none;
  }
  .product-cell {
    gap: 0;
  }
  .product-subtitle {
    display: none;
  }
  .product-upload-status.is-visible {
    display: block;
  }
  .product-upload-meter {
    width: min(9rem, 100vw - 8.25rem);
  }
  .product-name-row {
    max-width: 50vw;
  }
  .product-name {
    display: block;
    max-width: 100%;
    font-size: 0.84rem;
  }
  .table-actions {
    min-width: 4.25rem;
  }
  .capture-preview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .capture-actions {
    position: sticky;
    bottom: 0;
    padding: 0.75rem 0 0;
    background: var(--bg);
  }
  .capture-actions .toolbar-button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }
  .state-inline-form {
    flex: 1 1 100%;
  }
  .state-select {
    flex: 1 1 auto;
    width: auto;
  }
  .toast-region {
    right: 0.75rem;
    bottom: 0.75rem;
    left: 0.75rem;
  }
  .upload-toast {
    max-width: none;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .model-tool-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .model-measurements {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .model-measurements div:nth-child(2) {
    border-right: 0;
  }
  .model-measurements div:nth-child(-n+2) {
    border-bottom: 1px solid var(--border);
  }
  .model-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .model-form-grid {
    grid-template-columns: 1fr;
  }
  .model-form-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }
  .model-form-actions .primary,
  .model-form-actions .toolbar-button {
    width: 100%;
  }
  .card {
    flex-basis: min(72vw, 220px);
  }
  .product-images {
    grid-template-columns: repeat(2, 1fr);
  }
  .detail-image-card {
    flex-basis: min(72vw, 210px);
  }
  .row-pair {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    gap: 1.25rem;
  }
}
